Serin Problem

catalina

New Member
Would appreciate assistance with this coding problem, arising with two 08M's communicating wirelessly with Jaycar Tx & Rx modules

The serout routine from the sending 08M programme is,
Code:
alarm:					
	bit5 = 1
	bit6 = 0 
	serout 4,N600,(35,35,35,35,35,35,35,35,35,35,"TGA",bit5,bit6,bit6)
The syntax for entire sending code checks out okay and the simulation is okay. No problems there; the critical 1,0,0, should be output on output 4

The full code for the receiving 08M is
Code:
read1:
	
 	serin 4,N600,(35,35,35,35,35,35,35,35,35,35,"TGA",bit0,bit1,bit2)
	let bit3 = bit0 + bit1 + bit2

	serin 4,N600,(35,35,35,35,35,35,35,35,35,35,"TGA",bit4,bit5,bit6)
	let bit7 = bit4 + bit5 + bit6

	serin 4,N600,(35,35,35,35,35,35,35,35,35,35,"TGA",bit8,bit9,bit10)
	let bit11 = bit8 + bit9+ bit10

	let bit12 = bit3 + bit7 + bit11 
	if bit12 = 3 then alarm
	
Alarm:
	sound 1,(200, 50,0,50,100,50,0,50,50,100,0,50)
	wait 1
	goto alarm
The syntax checks out okay but the simulation runs to the serin command and pops up the Serin dialogue box, shown in the attachment.

No matter what data is placed in this box it either reports illegal serin data - try again or represents the box. What's wrong here.

The intention is to have port 4 read three times, putting 1's and 0's into the specified bits. Then after checking for receipt accuracy, set the alarm

I've looked at the manuals, the forum and David Lincoln's book but do not seem to find any answers. Would appreciate pointers to a solution.
 

Attachments

SD2100

New Member
Just trying to guess what your doing, if you want to set individual bits set them first then send the byte then at the receiver check the value, also on the receiver you are adding numerous bits to 1 bit that won't work also you don't need the preamble on serin.

Code:
'Send
Alarm:
    b0= %00010000
    b1= %00000000
    serout 4,N600,(85,85,85,85,85,85,"TGA",b0,b1)
Code:
'Receive	
read1:
    serin 4,N600,("TGA"),b0,b1
    if b0 = %00010000 and b1 = %00000000 then alarm1
    goto read1
 		
Alarm:
    sound 1,(200,50,0,50,100,50,0,50,50,100,0,50)
    wait 1
    goto alarm
Untested, just guessing
 
Last edited:

SD2100

New Member
If you want to verify that it has received the correct code 3 times you could do the following, the "pause 100" is to give the receiver some time to do it's thing before the next lot is sent

Code:
Alarm:
    b0= %00010000
    b1= %00000000
    for b2 = 0 to 2
        serout 4,N600,(85,85,85,85,85,85,"TGA",b0,b1)
        pause 100
    next
Code:
read1:
    for b2 = 0 to 2 
        serin 4,N600,("TGA"),b0,b1
        if b0 = %00010000 and b1 = %00000000 then CodeOk
        goto CodeError
CodeOk:
    next
	 		
Alarm1:
    sound 1,(200,50,0,50,100,50,0,50,50,100,0,50)
    wait 1
    goto alarm1

CodeError:
    goto CodeError
 

womai

Senior Member
You should use a DC balanced code as your preamble (i.e. equal number of ones and zeros), i.e. either 0x55 or 0xaa.

Second, don't use the preamble on the receive side. The preamble is only sent by the transmitter to "condition" the receiver. The detection of a packet is done using the qualifier ("TGA" in your case). I.e.

sender uses:

serout 4,N600,(0x55,0x55,0x55,0x55,0x55,0x55,0x55,"TGA",b0,b1)

receiver uses:

serin 4,N600,("TGA"),b0,b1


Wolfgang
 

catalina

New Member
Thanks Phil and Wolfgang for the comments.

Simulating with your suggestions results in the same Serin dialogue box popping up. When the data "TPG", 16,0 (ie b0=16,b1=0) is inserted in the box the simulation runs okay to the end of programme. Inserting "next" at programme end cause the simulation to jump back to start as expected but it halts at the serin command again awaiting another data input. I suppose this is to be expected as the simulation is not actually reading the input pin and needs the data specified to run on. Running with hardware the data would be read so I guess the simulation in this way proves the programme is okay.

Does this agree with your thinking?

Ken
 

SD2100

New Member
weenip yes, when you run the receiver code the simulator will stop on each pass through the loop at the serin and wait until you enter "TGA" plus the 2 byte values, if the byte values are correct then it loops again and the serin box reappears, if the byte values don't match the ones in the if/then statement then program will jump to the CodeError line where it will stay. Also if the qualifier "TGA" is incorrect then the program won't move past the serin.
 
Top