BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Fri Oct 19, 2018 9:08 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: serial communication from basicATOM 40 to BS1 prop1
PostPosted: Thu Dec 23, 2010 5:55 pm 
Offline
Citizen

Joined: Thu May 06, 2010 2:43 pm
Posts: 16
Hey there,

I have pin2 on my basicATOM chip connected to pin 7 of my BS1 (basic stamp 1) on the prop1 board. The grounds of both boards are tied together, although they use different power supplies.

The basicATOM is always the transmitting chip, and the BS1 prop1 is always receiving. A number from 1 to 9 is the data. Only ever one number at a time, and then a carriage return to show the end the number for the BS1.

This setup does not function. I can debug the BS1 and see that it is ready and waiting for action, and I can debug the ATOM and see that it indeed sends out the correct number from 1 to 9. But the BS1 does not seem to be receiving the information.

I have only tied grounds together and have the one serial wire. No resistors, caps, or anything else.

ATOM code:
Code:
if lvert>200 then '(if left forward)
   if rvert>200 then '(if right forward)
      serout P2, N2400, [dec 1, CR] '(left and right forward)
   elseif rvert<80 '(if right reverse)
      serout P2, N2400, [dec 3, CR] '(left forward and right reverse)
   else '(if right stopped)
      serout P2, N2400, [dec 2, CR] '(just left forward)
   endif
elseif lvert<80 '(if left reverse)
   if rvert>200 then '(if right forward)
      serout P2, N2400, [dec 4, CR] '(left reverse and right forward)
   elseif rvert<80 '(if right reverse)
      serout P2, N2400, [dec 6, CR] '(left and right reverse)
   else '(if right stopped)
      serout P2, N2400, [dec 5, CR] '(just left reverse)
   endif
else '(if left stopped)
   if rvert>200 then '(if right forward)
      serout P2, N2400, [dec 7, CR] '(just right forward)
   elseif rvert<80 '(if right reverse)
      serout P2, N2400, [dec 9, CR] '(just right reverse)
   else '(if right stopped)
      serout P2, N2400, [dec 8, CR] '(both stopped)
   endif
endif


and my basic Stamp 1 code:
Code:
' {$STAMP BS1}
' {$PBASIC 1.0}


'P1 = relay 1, M1 forward  (left)
'P2 = relay 2, M1 reverse
'P3 = relay 3, M2 forward  (right)
'P4 = relay 4, M2 reverse

SYMBOL direction = B2

Main:

  SERIN 7, T2400, #direction

  IF direction = 1 THEN bothforward
  IF direction = 2 THEN LforwardRstop
  IF direction = 3 THEN LforwardRreverse
  IF direction = 4 THEN LreverseRforward
  IF direction = 5 THEN LreverseRstop
  IF direction = 6 THEN bothreverse
  IF direction = 7 THEN LstopRforward
  IF direction = 8 THEN bothstopped
  IF direction = 9 THEN LstopRreverse

GOTO main

bothforward:
LOW 2
LOW 4
HIGH 1
HIGH 3
GOTO main

LforwardRstop:
LOW 2
LOW 3
LOW 4
HIGH 1
GOTO main

LforwardRreverse:
LOW 2
LOW 3
HIGH 1
HIGH 4
GOTO main

LreverseRforward:
LOW 1
LOW 4
HIGH 2
HIGH 3
GOTO main

LreverseRstop:
LOW 1
LOW 3
LOW 4
HIGH 2
GOTO main

bothreverse:
LOW 1
LOW 3
HIGH 2
HIGH 4
GOTO main

LstopRforward:
LOW 1
LOW 2
LOW 4
HIGH 3
GOTO main

bothstopped:
LOW 1
LOW 2
LOW 3
LOW 4
GOTO main

LstopRreverse:
LOW 1
LOW 2
LOW 3
HIGH 4
GOTO main


N2400 for the ATOM is: normal (non-inverted) data, no parity, 8 bits, high and lows driven by stamp, 2400 baud. Is this 1 stop bit also?

T2400 for the BS1 is: true data, no parity, 8 bits, 1 stop bit, 2400 baud.

Aren't these settings the same?
Any ideas on why this setup isn't working would be awesome. Thanks.


Top
 Profile  
 
 Post subject: Re: serial communication from basicATOM 40 to BS1 prop1
PostPosted: Thu Dec 23, 2010 7:10 pm 
Offline
Master

Joined: Tue Jun 22, 2010 9:15 pm
Posts: 228
You might try splitting up the problem, i.e., test each board separately.
Connect each to a PC running a terminal emulator (you'll need an RS-232 level conversion), and see if each talks/listens at 2400 Baud.

You can also try just flipping the "invert" on one or the other board.

Alan KM6VV

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


Top
 Profile  
 
 Post subject: Re: serial communication from basicATOM 40 to BS1 prop1
PostPosted: Fri Dec 24, 2010 3:17 pm 
Offline
Citizen

Joined: Thu May 06, 2010 2:43 pm
Posts: 16
The ATOM is definitely sending out the right number. I can hook it up to terminal on my PC and see the numbers flowing in correctly.

Additionally, The BS1 is definitely listening at serin. I can see it hang at the serin command, waiting for a number to come in.

I did try inverting each of the boards, using open drain instead of driven, etc. to no avail.

I looked it up in the manual, but still don't get it. What is the difference between open drain and driven?

Is the line held high (to 5V) with open drain, and then the ATOM sinks it to 0V, whereas the line is floating for driven, and the ATOM pulls it high to 5V and low to 0V? Or am I missing it?

Thanks.


Top
 Profile  
 
 Post subject: Re: serial communication from basicATOM 40 to BS1 prop1
PostPosted: Fri Dec 24, 2010 5:07 pm 
Offline
Master

Joined: Sun Oct 05, 2008 5:40 pm
Posts: 111
Try sending CR, LF or 13, 10 instead of just CR or 13.


Top
 Profile  
 
 Post subject: Re: serial communication from basicATOM 40 to BS1 prop1
PostPosted: Fri Dec 24, 2010 5:12 pm 
Offline
Citizen

Joined: Thu May 06, 2010 2:43 pm
Posts: 16
CR is a constant defined earlier in the program:
Code:
CR            CON     $0D     


but i also tried "A" without results. I will try your other suggestions though.


Top
 Profile  
 
 Post subject: Re: serial communication from basicATOM 40 to BS1 prop1
PostPosted: Fri Dec 24, 2010 6:09 pm 
Offline
Master

Joined: Tue Nov 21, 2006 5:34 pm
Posts: 662
If it were me, I would try changing to using only binary data. Since you are only needing to send a value from 1-9, this would be easy. Change Atom to do serout
like ...[1]
instead of ...[dec 1, cr]

On the BS1, I would then change code to remove the # from the serin. I would then debug I would probably print the value I received to verify that I got what I think I should have...

Kurt


Top
 Profile  
 
 Post subject: Re: serial communication from basicATOM 40 to BS1 prop1
PostPosted: Fri Dec 24, 2010 6:22 pm 
Offline
Citizen

Joined: Thu May 06, 2010 2:43 pm
Posts: 16
Okay, I removed the basc stamp and put another ATOM chip in its place.

Output code from transmitting ATOM:
Code:
serout P2/P3, NO2400, [dec 8,13] '(both stopped)


Complete code of receiving ATOM:
Code:
ant var byte
baudset var word

main

high p0
pause 4000
low p0
pause 500

serdetect P21,nomode,baudset
serin P21/P19,baudset,2000,expd,[dec ant]
if (ant = 8) then
   high P0
   pause 5000
   pause 5000
   low P0
   goto main
endif

goto main

expd
high P0
pause 200
low P0
pause 200
goto expd

end


As almost identical to the ATOM manual.

Layout:
P2 of the transmittingATOM is connected to P21 of the receivingATOM and a resistor to high (5V) is also connected at the rATOM's P21.
P3 of the transmittingATOM is connected to P19 of the receiving ATOM with no resistors to high or low.

If I only have the receiving chip turned on, then the LED lights for 4 seconds, then goes to fast blinking. If I turn on both transmitter and receiver, the LED lights for 4 seconds, then goes out permanently.

Is this setup correct? I will add an image shortly.


Top
 Profile  
 
 Post subject: Re: serial communication from basicATOM 40 to BS1 prop1
PostPosted: Fri Dec 24, 2010 6:42 pm 
Offline
Master

Joined: Tue Nov 21, 2006 5:34 pm
Posts: 662
Personally I have not tried the flow control on the output side, but it might just work...

I don't think you need to bother with the serdetect, unless you are really needing to use variable baud rates. And if you do, you then need to send a certain character to it, such that it can detect the baud rate sent...

I would also pre-initialize P19 to either low or high (have not looked close enough at the specs to know with your baud mode which one... This is needed such that the sending side sees the other side is not ready and waits for you to get into the serin.

Good Luck
Kurt


Top
 Profile  
 
 Post subject: Re: serial communication from basicATOM 40 to BS1 prop1
PostPosted: Fri Dec 24, 2010 7:10 pm 
Offline
Citizen

Joined: Thu May 06, 2010 2:43 pm
Posts: 16
Attached is my wiring diagram. kurt, I will try pre-initializing and post the results within the hour. I will also get rid of serdetect.

Question: Both baud rates get set the same, right? I will always use NO2400 for the transmitter. Can I set the receiver to NO2400 as well? Or should it be N2400? Or vice versa?

These seem like dumb questions (to me at least) but it didn't work to set them both the same. This issue is really frustrating, though it seems like it should be easy. Thanks for helping with this.

Attachment:
12-24-10-2atoms-serial.pdf [21.23 KiB]
Downloaded 422 times


Top
 Profile  
 
 Post subject: Re: serial communication from basicATOM 40 to BS1 prop1
PostPosted: Fri Dec 24, 2010 7:20 pm 
Offline
Citizen

Joined: Thu May 06, 2010 2:43 pm
Posts: 16
I am pretty sure the manual just answered my baudmode question with this note:
Quote:
Note: You may equally well use the baudmode constant described under
SEROUT for the SERIN command. The extra letter (O) will be ignored for
SERIN.


kurk, I had missed your earlier message, but am now working on getting the debugger to work. I have removed the "dec" modifier and "CR" from the serial output.


Top
 Profile  
 
 Post subject: Re: serial communication from basicATOM 40 to BS1 prop1
PostPosted: Fri Dec 24, 2010 8:27 pm 
Offline
Citizen

Joined: Thu May 06, 2010 2:43 pm
Posts: 16
Okay, now we are getting somewhere. But I'm not there yet.

my transmitter code:
Code:
serout P2/P3, N2400, [dec 8] '(both stopped)


my receiver code:
Code:
ant var byte
high 19
pause 1000

main

high p0
pause 2000
low p0
pause 1500

serin P21/P19,N2400,[ant]
debug ["hello",13]
debug [ant,13]
debug [ant,13]
debug [ant,13]
debug [ant,13]
pause 1000
high 0
pause 2000
low 0
pause 1000

if (ant = 8) then
   high P0
   pause 5000
   pause 5000
   low P0
   goto main
endif

goto main

end


With this setup, since the transmit baud is N2400 instead of NO2400, I removed the resistor to 5V from the circuit, because the transmitter drives the serial line high and low.

This setup blinks the LED twice, once for 4 seconds before the serin command, and once for 2 seconds after, and then repeats. It still will not light for 10 seconds when the right data is received. I have not figured out how to receive "8" from the transmit chip.

Before, all I could get was the first 4 second led light up and then the code would hang.

When I debug this, I see the "hello" then nothing when I am supposed to see the ant variable. Transmitting [dec 8] or [8] or [dec 8,CR] all give the same result (no recorded data in the ant variable). Any ideas?

Thanks.


Top
 Profile  
 
 Post subject: Re: serial communication from basicATOM 40 to BS1 prop1
PostPosted: Mon Dec 27, 2010 6:57 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 7:00 pm
Posts: 1316
Location: Temecula, CA
First let me point out that running in debug mode is VERY slow. You could very well miss whole bytes of data from the transmitter chip. I'd recommend using serout s_out instead of debug mode to debug the receiver chip. Also run the serout s_out at a high baudrate than your receiver chip is receiving data(eg 38400) so it can send debugging info to the PC much faster than it can receive data from the other processor.

Another thing, if you use serdetect(I don't think you are any more though), you have to send a specific bit pattern to the serdetect command or it won't correctly detect the baudrate.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


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

All times are UTC [ 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