communication between 2 microcontrollers
Hey you all.
This is my first project and I'm having some trouble communicating 2 BasicStamp2 Chips.
I need to make an automated traffic signal that read the time from another microcontroller (ideally a DS1302, but I only have another BS2)
the fact is that the serial communication with the PC works just fine, no problem, but when I try to communicate both BS2 it doesn't work.
this is the problematic part of the code:
traffic sign BS2:
and the clock:
when I'm debugging I just change the serial pin from 0 to 16 to read the data in my PC and send back data from my keyboard
I've tried with
SERIN 1/0 ..... and SEROUT 1/0 ..... (with straight and cross wires)
SERIN 1 ......... and SEROUT 1..........
and doesn't work
can someone helpme?
bst rgds
Angelo B.
(by the way, sorry for my poor english...)
Post Edited (Angelo Bernardi) : 11/30/2008 1:14:17 AM GMT
This is my first project and I'm having some trouble communicating 2 BasicStamp2 Chips.
I need to make an automated traffic signal that read the time from another microcontroller (ideally a DS1302, but I only have another BS2)
the fact is that the serial communication with the PC works just fine, no problem, but when I try to communicate both BS2 it doesn't work.
this is the problematic part of the code:
traffic sign BS2:
Horas: 'SEROUT 16, 16468, [noparse][[/noparse]CR,"ingrese hora"] SERIN 16, 16468, 1000, Horas, [noparse][[/noparse]DEC4 hora] 'comunicacion con PC 'SERIN 0, 16468, 1000, Horas, [noparse][[/noparse]DEC4 hora] 'comunicacion con reloj IF hora>(programa(0)*10)-1 AND hora<programa(1)*10 THEN 'ciclo peak 1 FOR contador = 12 TO 17 READ contador,tiempos(contador) NEXT GOSUB Ciclo ELSEIF hora>(programa(2)*10)-1 AND hora<programa(3)*10 THEN 'ciclo peak 2 FOR contador = 6 TO 11 READ contador,tiempos(contador) NEXT GOSUB Ciclo ELSEIF hora>(programa(4)*10)-1 AND hora<programa(5)*10 THEN 'ciclo peak 3 FOR contador = 6 TO 11 READ contador,tiempos(contador) NEXT GOSUB Ciclo ELSE 'sino entra en un ciclo peak, sigue en el ciclo normal FOR contador = 0 TO 5 READ contador,tiempos(contador) NEXT GOSUB Ciclo ENDIF RETURN
and the clock:
Main: DO SEROUT 0, 16468, [noparse][[/noparse]DEC4 tiempo] 'implementacion final 'SEROUT 16, 16468, [noparse][[/noparse]CLS, DEC4 tiempo, DEC2 segundos, CR] 'para efectos de debug TOGGLE LED PAUSE 483 SEROUT 0, 16468, [noparse][[/noparse]DEC4 tiempo] 'implementacion final 'SEROUT 16, 16468, [noparse][[/noparse]CLS, DEC4 tiempo, DEC2 segundos, CR] 'para efectos de debug segundos = segundos + 1 TOGGLE LED IF segundos > 59 THEN tiempo = tiempo + 1 IF tiempo > hora THEN tiempo = tiempo + 40 hora = hora + 100 ENDIF IF tiempo > 2359 THEN tiempo = 0 hora = 59 ENDIF segundos = 0 ENDIF PAUSE 484 LOOP END
when I'm debugging I just change the serial pin from 0 to 16 to read the data in my PC and send back data from my keyboard
I've tried with
SERIN 1/0 ..... and SEROUT 1/0 ..... (with straight and cross wires)
SERIN 1 ......... and SEROUT 1..........
and doesn't work
can someone helpme?
bst rgds
Angelo B.
(by the way, sorry for my poor english...)
Post Edited (Angelo Bernardi) : 11/30/2008 1:14:17 AM GMT
Comments
I suspect that there's some interaction between the SERIN timeout and the timing of the program that transmits the time. I also suggest that you test the program at a lower Baud (maybe 2400 Baud) since receiving at 9600 Baud is marginal with the BS2 as stated in the manual. The timing requirements are too difficult and it's very easy for the two Stamps to get out of synchronization at this higher speed.
Take a look at the IDE help files , there is an example of connecting two BS2's with flow control.
SEROUT and SERIN between the two stamps the baud rate needs to be true which for 9600 baud should be 84 (eg SEROUT·0,·84,·[noparse][[/noparse]DEC4·tiempo]··'implementacion·final and SERIN·0,·84,·1000,·Horas,·[noparse][[/noparse]DEC4·hora]··'comunicacion·con·reloj)
16468 is fine for P16
You are going to need some kind of flow control to synch the two, again read the help files and look at the examples and perhaps try simple first then implement the working results into your final program.
Jeff T.
·
I only have one more question: if I use flowcontrol, the sending BS2 (the one which is using SEROUT) will be wait forever if receive no answer from the other BS2? or the connection will be dismissed after some time?
Thanks for your help [noparse];)[/noparse]
I'll post here when I fix this issue.
Bst Rgds from Chile
Angelo B.
SEROUT does not permit a timeout parameter. Only SERIN uses a timeout parameter. Check the manual or the IDE Help file, and you'll see what I mean.
Regards,
Bruce Bates
PS Your English is OUTSTANDING!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When all else fails, try inserting a new battery.
Clock: SEROUT·0,·84,·[noparse][[/noparse]"!",DEC4·tiempo]··'implementacion·final
Traffic sign: SERIN·0,·84,·1000,·Horas,·[noparse][[/noparse]WAIT("!"),DEC4·hora]··'comunicacion·con·reloj
this way the clock keeps reasonable time, the drawback is slowing the traffic sign down a little
Jeff T.
What I'm really concerned about is that if the 'clock' sends (with flow control) the hour to the 'traffic sign', and the traffic sign isn't receiving at that moment, would the clock keep waiting until the traffic sign receives the data? or will just pass to the next instruction as if nothing were wrong?
If it's the first option, I will need some other way to do this, like doing it without flow control. If not, everything should work fine [noparse];)[/noparse]
About the WAIT instruction, it might not be necessary. In my debug tests all the transmissions were correct. When I debug I send the hour as a 4 digit decimal from keyboard, and the traffic sign executed everything as it should be. The clock also send the data to the PC with no problems (I read the data from the compiler's debug screen and from a visual basic program)
By the way, is there any restriction on the length of the interface wire between both BS2? I'm using a 14" 2 wire interface (2 wires from a 40wire IDE cable).
Bst Rgds
I'll try lowering the baud rate [noparse];)[/noparse] (tomorrow.... now it's about 0045hrs here and it was a very long day, so I want to sleep)
Thanks anyway [noparse];)[/noparse]
PS Bruce, I don't think so. It takes me kind a lot of time to write in English. But this is a very nice way to practice [noparse];)[/noparse]
i've tried everything
but there's not communication between both
it may be sincronization problem between both BS2, because when one is sending the other is not waiting for data.
I may solve this issue, but the clock will malfunction, because I can't guess when they will sincronize to calculate the pauses.
Meanwile, I'll try to solve this issue on the PC side. Because the traffic sign sends a 'ping' on every cycle asking for any instruction, and where there is need to make changes to the cycle, the PC application will send the instruction to the traffic sign.
I'll try to solve this on the BS2 code later this year, because I must have this working this week.
Tanks every one of you that helped me.
I'll keep in touch.
Bst Rgds
Angelo B.
If you decide to make the Traffic sign wait then the clock can continue its program cycle uninterupted which will keep the Clock BS2 as acurate as is possible·using a Stamp.
With any luck the time you lose waiting at the Traffic sign end will be negligible.
The WAIT instruction will synchronize the exchange of data but you may have to reduce the baud to 4800 for it to be reliable.
Jeff T.
using WAIT I don't need to use flow control?
I'll try this later [noparse];)[/noparse] now I'm making the circuit boards
By the way, the synchronization with the PC works just fine.
Jeff T.
·
Thanks
I'll try it later [noparse];)[/noparse]