' {$STAMP BS2px} ' {$PBASIC 2.5} '============================================MECCA SERVO =========================================== ' 8 bit, 2 stop bits, 2400 bps, hex output ' The Checksum byte is actually comprised of two 4 bit nibbles, the upper 4 bits and the ' lower 4 bits. The upper 4 bits are the actual checksum which is calculated based ON the ' values of DATA bytes 1 through 4. The lower 4 bits contain the Module ID number which is ' critical TO the entire bi-directional DATA stream. ' Each Smart Module receives the entire 6 Byte DATA packet AND THEN passes the exact same ' DATA packet down TO the NEXT module. There is no shared DATA bus. The DATA going ' upstream OR downstream must be sent through each Smart Module. ' The bits of each Byte coming from the MeccaBrain™ are approximately 417us long. A “1” ' Bit is 417us of HIGH; a “0” Bit is 417us of LOW. Each Byte has a start Bit (LOW) AND two ' STOP bits (HIGH). Also, the DATA bits are sent in REVERSE order. ' TO be clear, each DATA Byte looks like this ' {LOW, Bit 0, Bit 1, Bit 2, Bit 3, Bit 4, Bit 5, Bit 6, Bit 7, HIGH, HIGH} ' AND the entire DATA packet would look like ' {0xFF, DataByte 1, DataByte 2, DataByte 3, DataByte 4, Checksum/Module ID} spk PIN 5 led PIN 8 rx PIN 10 tx PIN 11 servo PIN 14 servoa PIN 15 y VAR Word x VAR Word s1 VAR Word s2 VAR Word s3 VAR Word s4 VAR Word header VAR Byte checksum VAR Word header = $FF checksum = $FC s1 = $FC s2 = %11111110 s3 = %11111110 s4 = %11111110 FREQOUT spk ,1000,1000 PAUSE 10 pref*ck: ' SEROUT servo,1646,[$FF, $FD, $FD, $FD, $FD,$FC] ' Checksum/Module ID} FOR x = 1 TO 20 'FOR y = 1 TO 10 SEROUT servo,1646,1,[header,s1,s2,s3,s4,checksum] ' Checksum/Module ID} 'SEROUT servo,1646,[header,%0111111101,%011111101,%0111111101,%011111101,checksum] DEBUG HOME, " ===>",HEX3 header," >",HEX3 s1," ",HEX3 s2," ",HEX3 s3," ",HEX3 s4," chk> ",HEX4 checksum," <=== ",DEC x ,CR, CR ' NEXT ' SERIN servo,1646,500,mode, [header,s1,s2,s3,s4,checksum] ' Checksum/Module ID} SERIN servo,1646, [WAIT ($FF),s1,s2,s3,s4,checksum] ' Checksum/Module ID} PAUSE 1 y = y+1 DEBUG " ===>",HEX4 header," >",HEX4 s1," ",HEX4 s2," ",HEX4 s3," ",HEX4 s4," chk> ",HEX4 checksum," <=== " ,DEC y,CR mode: NEXT 'PAUSE 100 ' mode: GOTO pref*ck