************************Problem Master Code******************************void setSPID( byte value ) {while ( !SPIS_SPTEF );SPID = value;}byte getSPID() {while ( !SPIS_SPRF );return SPID;}void main() {// setup for SCI here for serial port communication// setup SPI here; interrupts off// clear out anything in the slave bufferssetSPID( 0xff );getSPID();setSPID( 0xff );getSPID();setSPID( 0xff );getSPID();setSPID( 0x0a );getSPID();while ( true ) {byte i, b;do {SendMsg( "X" ); // SCI communicationsetSPID( 0x0a );b = getSPID(); // should always be a value between 1 and 6} while ( b == 0 );setSPID( 0x0 );b = getSPID(); // should always be a value between 1 and 6for ( i = 0; i != b; i++ ) {if ( i+1 == b )setSPID( 0xa );elsesetSPID( 0x0 );showVal( getSPID() ); // Should ALWAYS be 0. SCI communication.}// for pretty printingv[ 0 ] = '\r'; // SCISendMsg( v ); // SCIv[ 0 ] = '\n'; // SCISendMsg( v ); // SCI}}
************************Slave Code******************************void main() {byte z1=0;while ( 1 ) {byte val;WATCHDOG;val = getSPID();if ( val == 0xff ) continue; // ignore 0xff'sif ( val == 0x0 ) {setSPID( 0x0 );} else if ( val == 0xa ) {z1 = (z1 + 1) % 6;setSPID( z1 + 1 );} else {setSPID( val ); // this line never executes as a part of the test}} /* loop forever */}
**************************New Master getSID and setSPID*************void setSPID( byte value ) {byte x;while (!SPIS_SPTEF );SPID = value;// MINOR DELAYx = 0;do {x++;}while ( x != 20 );}byte getSPID() {byte x;while ( !SPIS_SPRF );// MINOR DELAYx = 0;do {x++;}while ( x != 20 );return SPID;}
Message Edited by Alban on 2007-01-17 09:09 PM