Serin problem (bits incorrect?)

Hi all,

I am working on this project for school, and I have a CMUcam3 hooked up to my bot board 2, and hooked up to my bluesmirf which are working well, but I have a problem that I’m not getting the correct output from the CMUcam3.

I have my CMUcam3 on pins 10 and 11 on my bot board, I have the bluesmirf on pins 14 and 15 (using hserial).

There are some interesting things that occur that I cannot explain, but I just run with them because they work. First you need to know a little bit about the CMUcam3. When I send “HR 1” to the tx pin of the CMUcam3 it returns “ACK\r” to tell me that the code was received correctly.

I can use this to check if the camera is connected to the bot board 2, which is what I do, the actual code I run on the bot board is shown:

[code]bsmirfBaud con H9600
SETHSERIAL1 bsmirfBaud

pcBaud con i9600
pcTx con s_out
pcRx con s_in

speaker con p9

val var byte ’ Variable for sound routines

camBaud var pointer(2)
camTx var pointer(2)
camRx var pointer(2)

camBaud(0) = i9600
camTx(0) = p11
camRx(0) = P10

main
'Play Boot sound
for val = 2 to 5
sound speaker, [val30\val1000]
next

pause 1000

serout camTx(0), camBaud(0), "HR 1",13]
gosub camAckno [0]

'Play connected to camera sound
for val = 5 to 12
	sound speaker, (val*5)\(val*(random tca))]
next


loop
	
	gosub bsdata command
	
	serout pcTx, pcBaud, "Recieved: ", command]
	
	if command = "A" then
		serout camTx(0), camBaud(0), "SJ", 13]
		gosub camAckno [0]
		
		for val = 5 to 12
			sound speaker, (val*5)\(val*(random tca))]
		next
		
		gosub camGetJpg [0]
	endif
	
	if command = "B" then
		serout camTX(0), camBaud(0), "HR 1", 13]
		'gosub camAckno [0]
		
		'for val = 5 to 12
		'	sound speaker, (val*5)\(val*(random tca))]
		'next
		
		gosub camGetVersion [0]
	endif

goto loop

end

’ wait for ACK from cam 1
camAckno [camAcknoArg]
serin camRx(camAcknoArg), camBaud(camAcknoArg), [wait(“ACK”)]
serin camRx(camAcknoArg), camBaud(camAcknoArg), [packet] 'grabs the return after the ACK that confused me! this was the big fix
return

’ get command from bluetooth
bsdata
hserin [wait(“BB2”)]
hserin [command]
hserin [packet]
return command

camGetVersion [camGetJpgArg]

versionIndex = 0

camVersionLoop

	serin camRx(camGetJpgArg), camBaud(camGetJpgArg), 20000, camGetVersionTimeout, [version(versionIndex)]		'get a byte from camera
	
	versionIndex = versionIndex + 1
	
	'hserout [version(versionIndex-1)]
			
goto camVersionLoop

camGetVersionTimeout

if version(0) = "A" and version(1) = "C" and version(2) = "K" then
hserout "TITS"]
endif

hserout [str version\30]

return
[/code]

I’ll shortly explain what is going on, basically I send the “HR 1\r” to the camera and then go into the camAckno subroutine, which waits for the ACK from the camera, this works and I get to hear the 2nd jingle from the botboard2. However there is a catch. The first time the board is reset after it is programmed it will not play the 2nd jingle and not connect, the second time it will also not connect (and sit in the loop waiting for ACK forever) and so it will also not play the 2nd jingle. However the 3rd time it is reset it will connect. I don’t know why but every 3rd time it connects, and every time after the 3rd time it also connects.

Once it has connected I can give a command from the bluesmirf which also outputs the command to the PC to be sure it received it, if I give the command “BB2B” then it goes and tries to get the ACK byte by byte. Which always fails. I get patterns like AC¥Ã or A¡©ø (almost those two exclusively) instead of getting ACK\r. I have converted the chars to a series of bits and they look like the following:

[pre]ACK\r 01000001010000110100101100001101
AC¥Ã 01000001010000111010010111000011
A¡©ø 01000001101000011010100111111000[/pre]

As you can see in the 2nd example the pattern is very similar but it is getting a couple 1’s that are off. I never get the ACK\r, only the other two.

I am sure that the baud rates are setup correctly I went into the bluesmirf and calibrated it for 9600, the PC serial programs are running at 9600 (lynxterm) and the camera is running at 9600 also.

Here is another interesting thing that I was hoping someone could answer. When I try to read the bytes from the camera when it is sending the “ACK\r” I get the bad versions as I said above. However I am sure that it is sending the “ACK\r” correctly, because I get the jingle which I can only get when it does the wait(“ACK”) and receives the ACK. So I am sure that the ACK is sending correctly, but the wait() command must receive differently from receiving bytes directly because I get different results. I know that it is actually getting ACK because when I change wait(“ACK”) to wait(“AAA”) it never does the 2nd jingle, even after 3 resets.

If anyone has experience with this, then please help me. I am very happy to provide more information, and when this is all said and done it will be good for other people to have solved these problems.