BasicMicro - Forums

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

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Nano 28 Hardware Serial Syntax Question
PostPosted: Fri Oct 29, 2010 9:14 pm 
Offline
Citizen

Joined: Tue Feb 10, 2009 9:41 pm
Posts: 7
Greetings All,
I am having trouble finding the correct syntax for Hserial on the Nano28.
When I compile the following

Code:
hserin 1, main, 8000,[indata]


I get this error

Quote:
Error: FILE C:\DOCUMENTS AND SETTINGS\HIS\DESKTOP\RFID PROJECT\RFID REV0.BAS(LINE 10) : [TOKEN MAIN] : Expected [



Thanks for any help.


Top
 Profile  
 
 Post subject: Re: Nano 28 Hardware Serial Syntax Question
PostPosted: Fri Oct 29, 2010 9:53 pm 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
Hello, angryone. Try dropping the "1" after "hserin":
Code:
hserin main, 8000,[indata]

In their attempt to unify the code between all the Atom parts, and having the BAP40 contain two USARTs, the coder(s) at BMicro are going to hserial1 and hserial2. Apparently they haven't "melded" all this entirely. I had to use the "1" with "sethserial", but not elsewhere.
My code compiled to completion under Studio 2004 on one PC (XP Pro), and looks like:
Code:
indata var word

enablehserial
sethserial1 h9600  ; this is all you need for a Nano chip, Pro needs more
hserin1 nomore, 10000, [indata]

nomore
;place timeout code here

Mind you, I haven't actually run this in a real circuit.

However, I can't do a compile to completion on the PC with XP Home and Studio 2000. It goes to compile, the Task Manager shows 100% CPU use, and then things just stay at that state. I exit Studio, but the MBasic.exe stays open under "Processes". I have to kill that to get my CPU usage to go back to its usual 0 to 10% levels. Other programs compile OK.

Try again and let us know how it goes.

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


Last edited by kenjj on Fri Oct 29, 2010 10:29 pm, edited 2 times in total.
Update test results on other PC.


Top
 Profile  
 
 Post subject: Re: Nano 28 Hardware Serial Syntax Question
PostPosted: Sat Oct 30, 2010 6:46 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 527
kenjj wrote:
Code:
indata var word

enablehserial
sethserial1 h9600  ; this is all you need for a Nano chip, Pro needs more
hserin1 nomore, 10000, [indata]

nomore
;place timeout code here

Hi Ken, I compiled on for Nano on build 2.0.0.4 and as you mentioned you need to remove the 1 from hserin1. The above gave me compile errors:
Code:
Error: FILE C:\USERS\KURT\DESKTOP\LYNXMOTION\XXX.BAS(LINE 39) : [TOKEN HSERIN1] : Unknown Command

Disregard the line number I put this at an end of a dummy file, with everything else #ifdefed out...

Without the line being hserin, it built fine on my machine... I did not download it either...

Ken, FYI It does not appear like I am getting the CPU spike that you mentioned..

Kurt


Top
 Profile  
 
 Post subject: Re: Nano 28 Hardware Serial Syntax Question
PostPosted: Sat Oct 30, 2010 12:11 pm 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
Pfft. That's what I get for working between two PCs. So I did it without the "1" (just "hserin"") and it compiled OK, then went back to my PC with the forum post opened and typed in the whole thing and used the "1". *sigh*
Corrected copy:
Code:
indata var word

enablehserial
sethserial1 h9600  ; this is all you need for a Nano chip, Pro needs more
hserin nomore, 10000, [indata]

nomore
;place timeout code here

Try this, it should compile. Still haven't run it, though.

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


Top
 Profile  
 
 Post subject: Re: Nano 28 Hardware Serial Syntax Question
PostPosted: Sat Oct 30, 2010 1:35 pm 
Offline
Citizen

Joined: Tue Feb 10, 2009 9:41 pm
Posts: 7
Awesome! Thanks a bunch. It compiled for me and I will be trying it shortly.

Ill keep you posted.


Top
 Profile  
 
 Post subject: Re: Nano 28 Hardware Serial Syntax Question
PostPosted: Sat Oct 30, 2010 11:14 pm 
Offline
Citizen

Joined: Tue Feb 10, 2009 9:41 pm
Posts: 7
The code above totally works! I cant thank you enough!

I have it looping back the string I send.

The project I am working on uses an RFID reader to allow a car to start. I am having trouble with the identification of the tags. The reader sends a 12 digit ASCII string terminated by a carriage return and line feed.

How would I store and read the string?


Top
 Profile  
 
 Post subject: Re: Nano 28 Hardware Serial Syntax Question
PostPosted: Sun Oct 31, 2010 7:28 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 527
I am not sure, what you are asking in your last message. Are you asking how can I save away a value that I can reuse later?

If you are wanting it short term, that does not persist when the processor is rebooted, you can simply keep it in memory. Possibly an array of values.

If you are instead wishing for it to persist, than use the 256 byte EEPROM that is part of this chip. You can access it using the ReadDM (or Read) and the writeDM (or Write) commands. I have not used the EEPROM on Nanos, but some of the chips you can only write up to a maximum of 32 bytes at a time and sometimes can get into issues if a multibyte write crosses a 32 byte boundary. Not sure with Nano, but I try to avoid that situation.

Also note with EEPROMS versus normal memory. They are slower to access and they typically have a maximum number of times that they can be written to... This has never been an issue for me, but I would not use it to hold a value that I constantly change...

Edit: If the strings you are wishing to use are hard coded and not changing, you can also define them using something like a: bytetable
Unless the strings you are using are of some constant length, I will typically either define them with a known terminator character at the end or I will use the first element to store the length...
Note: I do the same when I store stuff on the EEPROM.

Good Luck
Kurt


Top
 Profile  
 
 Post subject: Re: Nano 28 Hardware Serial Syntax Question
PostPosted: Sun Oct 31, 2010 11:27 pm 
Offline
Citizen

Joined: Tue Feb 10, 2009 9:41 pm
Posts: 7
Thanks Kurt. I had to search a bit on how to do it, but the byte table did the trick. :D

My strings are of a fixed format, so I have 2 different "if" statements looking at a number of specific cells in the byte table for 2 "allowed" cards. When there is a match, the 28 turns a relay on.

I have been testing it for a few hours now, debugging the final code. I have it in a state where it works 100% of the time. I'm currently in the process of writing a script to test my hardware design by turning the relay off and on repeatedly for 1 second intervals. My plan is to let it run all night, if it survives, then I can be confident that it will work in a friends car for a while.

Thanks again to all of you. I appreciate the help and I couldn't have pulled this off with out the help. :)

-Bill


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO