Javelin to BS2 communication.
Kevin B Slater
Posts: 49
· I am connecting a Javelin to a BS2 using N&V article number 81, A Tale of Two Stamps, as a guide.· My question is can I use·2 pins·to do this.· I know that you have to declare a Uart on the Javelin as a receive or a transmit.··I believe I will have to use·three pins because of this, but was wanting to know if it could in fact be·done with two.
Thanks,
Kevin
Thanks,
Kevin
Comments
Thanks for any input.
Kevin
And isn't it possible to just use one Uart with one pin to send and receive data from the bs2? I'm almost at 6 VP's and 16 pins and need efficiency.
and vice versa. That way you only require 1 pin.
However, let the BS be the master and use a halfduplex request/acknowledge protocol,
so the BS does not miss any transmission.
Example:
BS sends <COMMAND><data1><data2>...
Javelin responds with <resp1><resp2>
COMMAND,data1,data2,resp1,resp2 are bytes and to be defined by your
protocol. How many bytes are transmitted or received is up to you.
At least you should have commands for
a. Data available (to inform javelin the BS has data for the javelin)
b. Data required (to inform javelin the BS requires data from the javelin)
Note that it is the BS that initiates transmission and that the javelin
always responds.
So the BS has a sequence
· SEROUT ...
· SERIN ...
wheras the javelin has a sequence
· if (BSIO.bytreAvailable()) {
··· receive·COMMAND and databytes
··· process command
··· BSIO.setDirection(Uart.dirTransmit);
··· send response
··· while (!BSIO.sendBufferEmpty()) ; //wait for transmission completed
··· BSIO.setDirection(Uart.dirReceive);
· }
Note that the javelin response may be the response of a previous processed·command
so the BS does not have to wait for the current command to be processed.
In that case you should index your commands and responses so responses can be matched to commands.
Again, this all depends on how you define your protocol.
regards peter
Now the main part of the bs2 code:
I have attached the full BS2 code if it helps.
I have some general questions too, should both the stamps match on inverted/ not inverted? Is one better than the other? Also, what is a good speed?
I also noticed that if the BS2 doesn't get a response back after a second or so it executes the rest of the code. Isn't that a problem if my javelin's main loop takes, say 2 seconds, so it wont reach the "byteAvailable()" statement in time before the BS2 moves on?
For the BS code, try this
Main:
··DEBUG·"byte:·"
··DEBUG·DEC receivedByte
··SEROUT·JavIO,T2400,[noparse][[/noparse]receivedByte]
··SERIN·JavIO,T2400,[noparse][[/noparse]receivedByte]
··GOTO·Main
END
You just want to send the receivedByte, not its decimal ascii representation.
I am not sure if the BS2 supports a timeout on serin.
If it does, you can use that to identify a not responding javelin.
Do you get any results in the BS debug window?
regards peter
byte: 2byte: 4byte: 8byte: 16byte: 32byte: 64byte: 0byte: 0...
Apparently, the "1+receivedByte" statement adds a 1 bit onto the end, and does not increment the number by 1. How can I fix this?
Now I just want to make sure about some things before I set up my protocol. Here is what I have for the javelin:
if (BSIO.byteAvailable()) {
receiveByte() //the COMMAND
while(byteAvailable())
receiveByte() and store
process command
BSIO.setDirection(Uart.dirTransmit);
sendByte( );
sendByte( );
...
sendByte( );
while (!BSIO.sendBufferEmpty()) ; //wait for transmission completed
BSIO.setDirection(Uart.dirReceive);
}
And for the BS2:
SEROUT JavIO,T2400,[noparse][[/noparse]COMMAND,byte1,byte2,....]
SERIN JavIO,T2400,[noparse][[/noparse]receivedbyte1,receivedbyte2,...]
Would it work/be easier to always receive a preset number of bytes and to always transmit a set number of bytes so there is no need to send commands that say data is available or needed? I am trying to keep this as simple as possible.
I also think you need a pullup resistor of 10k on the data line.
In invert mode the rest level is high.
So the BS starts with IO line high, then goes low (startbit),
does the bits and then goes high (stopbit). Then the BS
changes the IO to an input (SERIN). Because the javelin
also is an input then, the IO line would float without the pullup.
Due to the pullup the IO level remains high.
When the javelin changes the IO to an output to transmit
its response, it outputs a high (rest level), then low (startbit),
does the bits and then high again (stopbit).
So with a pullup and invert mode the IO level is always high
when changing pin direction. Make sure the baudrate constant
for the BS2 is also for inverted mode.
Before deciding on the exact protocol, you must get the communication
working. The 1+receivedByte simply adds 1 to the received value
and does not double it (if 2 is received, the response is 3).
Add a delay after SERIN in the BS. This allows for the javelin
to change the uart direction back to receive.
Use a pause 1000 for a 1 sec delay.
regards peter
using a single javelin. Pin2 acts as master, pin3 as slave.
Both pins 2 and 3 have 4.7k pullup resistor.
Pins 2 and 3 are connected via 1k resistor.
The program works only using Uart.dontInvert mode,
which makes me believe the dontInvert mode has
a high rest level (I thought invert mode had this).
regards peter
Post Edited (Peter Verkaik) : 8/3/2006 10:16:12 AM GMT
what exactly do you want you the bs2 and the javelin to do?
I assume you want to exchange data between the two
but it is easiest if we know what you try to accomplish.
regards peter
For sending the switch data, I only need 1 byte, and for receiving the data for the motorcontrollers, I could also do it with 1 byte (There will be fewer than 8 pins needed for motor control). If done this way, I would only need to transmit 1 byte to my javelin, and have it respond by sending another byte back.
I guess I need to know how to make a data byte that would have bits reflecting the states of my 5 switches. For my javelin, I think I will use this statement for decoding the byte:
(receivedByte & (1<<switchNumber) ) == 0
And for the javelin's transmission back to the bs2 with the data for the motor controllers, I can just set up a simple number system code, like 1 = turnOn motor #1, 2 - turn on lights, 3 = turn on motor and lights, etc since there are only a few tasks to do. This would simplify it somewhat since the action of turning on a motor would require 3 pins.
Any suggestions?
The BS2 sends a byte holding button states, the javelin responds with a byte
holding the L293D states. I checked the L293D datasheet and it only requires
4 control bits + 2 enable bits. If permanently enabled, only 4 bits are required
for the L293D, leaving 4 bits for other purposes.
The BS2 may send at will, so it should send the button states frequently
enough so the javelin can send updated L293D data to the BS2 often enough
for your application.
regards peter