BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 12:33 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Problems with SETHSERIAL
PostPosted: Sat Nov 27, 2010 9:18 am 
Offline
Guru

Joined: Sun Jan 03, 2010 8:01 am
Posts: 55
Location: Eau Claire, WI
Greetings all,

I am in the process of trying to interface a serial based LCD display with my Nano-40. I actually have two questions for the experts out there (I have spent a fair amount of time also doing some research and scanning the Atom manuals but I just can't seem to get my code working). As you can see I've used Kenjj's code for testing purposes

1) How/Can I configure SEROUT to send data using the following parameters:
8 data bits
no parity
1 stop bit
non-inverted

2) So I decided to use the HSEROUT/HSERIN commands seeming I can specify the serial parameters but this is what I end up with...

The following error is generated when I use these commands

indata var word

SETHSERIAL1 H9600,H8DATABITS,HNOPARITY,H1STOPBITS
hserin nomore, 10000, [indata]

nomore
;place timeout code here

Error: FILE D:\BM\XBEE\HSERIAL.BAS(LINE 7) : [TOKEN H9600] : Unexpected token type

The code below runs fine but I need to specify the serial parameters listed above!

indata var word

SETHSERIAL1 H9600
hserin nomore, 10000, [indata]

nomore
;place timeout code here

I am using both Windows XP (SP3) and Windows 7 Professional using V2.0.05. Any insight or help would be greatly appreciated by me (and my family) as I have over 6 hours working on this project this weekend (so far) :evil: . It is really hard trying to interface something to a stamp when you are still trying learn how to program (again) and learn how something new works!

Thanks much-Brian

PS: Promise to post code on how to interface 4D Systems uLCD touch display when I get it working!


Top
 Profile  
 
 Post subject: Re: Problems with SETHSERIAL
PostPosted: Sat Nov 27, 2010 9:30 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 527
Hi, I am more knowledgeable with the Atom Pros, but have done some playing now with a Nano.

1) Serout is easy.
First try: serout mypin, N9600, [...]
As not everything appears to have the same feeling about what is inverted or not, if the above does not work try:
Serout mypin, I9600, [...]

2) The hardware serial ports on the PICS only allow you to set the baud rate, as such the only parameters valid on the Nano or Atom is the baud rate. So try:
SETHSERIAL1 H9600

Good Luck
Kurt


Top
 Profile  
 
 Post subject: Re: Problems with SETHSERIAL
PostPosted: Sat Nov 27, 2010 9:51 am 
Offline
Guru

Joined: Sun Jan 03, 2010 8:01 am
Posts: 55
Location: Eau Claire, WI
Thanks for the quick response Kurt!

Just to verify...using the NANO you can only specify the baud rate; you cannot specify other serial parameters such as start/stop bits or parity when using the HSEROUT?

I still don't understand how to configure start/stop and parity with the SEROUT command (this can be done?)

Until I am able to specify these serial commands I will not be able to communicate with my serial-based LCD display (remember I need to specify 8 data bits, no parity and 1 stop bit)....I don't I'm out of the woods yet....


Top
 Profile  
 
 Post subject: Re: Problems with SETHSERIAL
PostPosted: Sat Nov 27, 2010 10:02 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 527
Brian wrote:
Until I am able to specify these serial commands I will not be able to communicate with my serial-based LCD display (remember I need to specify 8 data bits, no parity and 1 stop bit)....I don't I'm out of the woods yet....

Those are all pretty well the defaults. Again I have not interfaced a serial LCD with a Nano, but have done this many times with Atom Pros.

For example the N9600 is 8 bit no parity non-inverted... If you have not already done so you should download their updated (beta version) manual: http://downloads.basicmicro.com/downloa ... l_V1_0.pdf

Kurt


Top
 Profile  
 
 Post subject: Re: Problems with SETHSERIAL
PostPosted: Sat Nov 27, 2010 3:04 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
The Nano/Atom hserial commands are 8bit no parity and 1 stop bit always. So H9600 is 9600bps at 8bits/no parity/1 stop bit.

Also you can not specify the inverted/non-inverted nature of the hardware serial ports. You should test whether this may be the problem by using the software serial commands(serout) with n9600 and i9600 as the baudrate. If n9600 works then you need to add a hardware inverter if you want to use the hserial commands.

This could also indicate your serial LCD is designed to connect directly to a PC rs-232 port which uses +-12v levels inverted from the TTL levels. In that case use a MAX232 conencted to the Nanos hardware serial port.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: Problems with SETHSERIAL
PostPosted: Sat Nov 27, 2010 7:56 pm 
Offline
Master

Joined: Tue Jun 22, 2010 1:15 pm
Posts: 203
I'm playing with a nano18 on a Nano Driver board. Parallax LCD.

Code:
Display         con P10      ;   
DisplayBaud      con   9600   ; Parallax can be set up for 2400, 9600 or 19200 baud

LcdCls          CON     $0C             ' clear LCD (use PAUSE 5 after)
LcdBLon         CON     $11             ' backlight on
LcdBLoff        CON     $12             ' backlight off
;LcdOff          CON     $15             ' LCD off
LcdOn1          CON     $16             ' LCD on; cursor off, blink off

pause 500   ; delay for LCD startup

  high Display   ; setup serial output pin
  pause 100      ; allow LCD to initialize
;
  serout Display, DisplayBaud, [LcdBLon, LcdOn1, LcdCls]
  pause 250
  serout Display, DisplayBaud, ["Nano Bot"]


Seems to work!

Alan KM6VV

_________________
Visit:
http://groups.yahoo.com/group/SherlineCNC/
http://tech.groups.yahoo.com/group/HexapodRobotIK/


Top
 Profile  
 
 Post subject: Re: Problems with SETHSERIAL
PostPosted: Sat Nov 27, 2010 8:07 pm 
Offline
Master
User avatar

Joined: Tue Jul 07, 2009 9:06 am
Posts: 120
Location: Wisconsin USA
sethserial is broken for the nano in 2.0.0.5
It either stops the program from running, or just causes it to run incorrectly.
I'm still waiting for Acidtech to fix that. I keep checking for 2.0.0.6 but, haven't been able to download yet.

_________________
Image
Basic Micro Blog
Universal Robot Controller


Top
 Profile  
 
 Post subject: Re: Problems with SETHSERIAL
PostPosted: Sun Nov 28, 2010 4:34 am 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
I tested this HSERIAL problem. Only the Nano18 has problems. The Nano28 was OK, and by extension, I'd say the Nano40 is also probably OK. The N18 is an entirely different PIC from the N28 and N40. The -18 is a PIC16F88, while the -28 and -40 are the PIC16F886/-887, which are largely the same guts. ;)
Later.

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
 Post subject: Re: Problems with SETHSERIAL
PostPosted: Sun Nov 28, 2010 8:02 am 
Offline
Guru

Joined: Sun Jan 03, 2010 8:01 am
Posts: 55
Location: Eau Claire, WI
Greetings all,

Thanks for the code examples, hints, and verification of default/preprogrammed serial settings from everyone! This has been one of the most helpful forums that I have been assoicated with (and best behaved)....now if eveyone would just read the manuals ;)

I am able to use the HSERIN/HSEROUT commands to communicate with uLCD-144 (LCD) but for some reason the SERIN/SEROUT commands do NOT work (I am not able to send a simple U which sets up LCD Display for AUTOBAUD and is the required first step for establishing comunication).

Is there a technical issue with "how" the HSER/SER-based send serial data...do they both conform to (or other insight is to what the differances between why one command would work over the other)?
8-data bits
1-stop bit
no partity

I don't want to start another thread but I was going to use the Nano-18 to control my LCD so is there an ETA on when the SETHSERIAL will be resolved?

Also on a side note: IT IS SO NICE BEING ABLE TO USE FLOATING POINT MATH (for less than $10) on a CPU which is key in my application (converting temps from C to F and adding/subtracting values)! Gotta love the Nanos!

Sorry for the long posts-Brian


Top
 Profile  
 
 Post subject: Re: Problems with SETHSERIAL
PostPosted: Sun Nov 28, 2010 8:43 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 527
Brian wrote:
Is there a technical issue with "how" the HSER/SER-based send serial data...do they both conform to (or other insight is to what the differences between why one command would work over the other)?
8-data bits
1-stop bit
no parity

Slight background: For each character there are 10 bits of data a start, the 8 data bits and a stop. So at 9600 baud each bit is 1/9600 seconds long or about 104us.

With the hardware serial port this is done with hardware support. That is the UART you hand it a byte of data to output and it takes care of timing of all of the bits, likewise when data is coming in. Also with the HSERIAL system it goes one step farther. That is, when you tell it to output a string of characters, it simply queues these up and the hserial system, than puts a character into the the appropriate register to start the output, when the system then says it is ready for another character, it generates an interrupt, which the hserial system than gives it the next... Likewise for input. When the system has detected a new character has arrived, an interrupt is generated and that character is added to a queue and the system can continue to receive the next character. This allows you to read in the characters whenever your code wishes to. Why use this: The timings are taken care of for you. The hardware queues allows your program to do other things while the characters are being input or output... Likewise as the characters are input or output with hardware support, they are not potentially screwed up by other things like interrupts that happen on the processor (within reason)

With the Serin/Serout system, this is all done in software. When you tell the system to output a string of characters, the serout function will start to output: Set the start bit(high or low depending on normal or inverted), spin for 104us, output the first bit, spin for 104us, ... Likewise for serin, the code will sit there spinning wait for the start bit transition, when it detects it, it will spin for 1/2 bit period in this case 52us, such that it will detect the bits as close to what it thinks the center of the bit is and then it will delay a bit period, detect the first bit, delay, detect... With this, if data is being sent to the pic and your program is not in a serin statement, that data will be lost...

When use serin/serout: There are a limited number of hardware serial ports that are fixed to specific pins. Likewise, with the hardware serial port code you are limited to what the hardware can do(which baud rates, parity, stop bits, inverted or non-inverted...) where with software you are free to implement whichever options you wish, only limited by how fast can the code go...

Downsides include: Your processor will sit there spinning while waiting to input/output a bit. All characters that are received when you are not in a serin are lost. Serin/Serout data can be screwed up if your code is processing any interrupts. This includes interrupts for hserial or on Pros Hservo... Why: I have mentioned this in many other places...

I hope my longer winded response, answers you question :lol:

Kurt


Top
 Profile  
 
 Post subject: Re: Problems with SETHSERIAL
PostPosted: Sun Nov 28, 2010 11:58 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
So basically there are 2 possibilities. You have the inverted/non-inverted baudrate set incorrectly in the software serial commands. If hserial commands work then you should use iBaudrate(eg i9600) instead of nBaudrate(eg n9600) for serout.

Or like Kurt suggested you may be running some other commands that use interrupts which can cause the timing on software timed commands like serout to get messed up. The hserial system runs an interrupt in the backend so if you are using both serial and hserial commands at once this could be causing your problem.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO