Code:
void SendAndWait( U8 data )
{
if ( MA_OK != MA_PutChar_SPI( data ) );// cout<<"DAMN!";
//else cout<<"OK! ";
while( MA_OK!=MA_TestChar_SPI() );
//cout<<"LOOP DONE!";
}
void Init_Ism( int send )
{
PORTB |= 0x20; //CS = 1
wait(200); //wait
//char Init_ShockBurst_DATA2W[8]= how much bits do you send? see send-function!
SendAndWait( 0x20 ); //I decided to leave this value unmodified, but write a function, that send only four bytes - 32 bits!
//char Init_ShockBurst_DATA1W[8]=
SendAndWait( 0x20 );
//char Init_ShockBurst_ADDR2[40]= Adress Channel 2
SendAndWait( 0xBB); SendAndWait( 0xBB); SendAndWait( 0xBB);
SendAndWait( 0xBB); SendAndWait( 0xBB);
//char Init_ShockBurst_ADDR1[40]= Adress Channel 1
SendAndWait( 0xBB); SendAndWait( 0xBB); SendAndWait( 0xBB);
SendAndWait( 0xBB); SendAndWait( 0xBB);
//char Init_ShockBurst_ADDRW[6]=
//{0,0,1,0,0,0};
//char Init_ShockBurst_CRC[2]=
//{0,1};
SendAndWait( 0xA1);//84 Binary Add ADDRW & CRC
//char Init_ShockBurst_RFPROG[16]=
//{0,1,0,0,1,1,1,1,0,0,0,0,0,1,0,0}; divide into 2 Byte á 8 bit and send away
SendAndWait( 0x4F);
if ( send == 1 ) SendAndWait( 0x04); //to receive, switch last bit to 1, 0 means transmit
if ( send == 0 ) SendAndWait( 0x05);
PORTB &= ~(0x20); //set CS = 0
wait(200); //wait
}
void sendMsg( char *string )
{
char part[4] = { ' ', ' ', ' ', ' ' };
int length;
int i;
//Message to UART0
cout<<"Sending Message...\n";
length = strlen( string );
for( i = 0; i<length; i++ )
{
if ( i == 0 )
part[0] = string[i];
if ( (i % 4) == 1 && i != 0 )
part[1] = string[i];
if ( (i % 4) == 2 && i != 0 )
part[2] = string[i];
if ( (i % 4) == 3 && i != 0 )
part[3] = string[i];
if ( (i % 4) == 0 && i != 0 )
{
sendMsgPart( part );
part[0] = ' '; part[1] = ' ';
part[2] = ' '; part[3] = ' ';
part[0] = string[i];
}
}
sendMsgPart( part );
//Show the transmitted message
cout<<string<<"\n";
}
void sendMsgPart( char *string )
{
PORTB |= 0x10; //CE = 1
wait(200);
//ShockBurst_ADDR1[40]=
//{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
//0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
//1,1,1,0,0,1,1,1}; prepare the Addess Channel to send some information
SendAndWait(0xBB);
SendAndWait(0xBB);
SendAndWait(0xBB);
SendAndWait(0xBB);
SendAndWait(0xBB);
//lähetettävä viesti Send your information here
SendAndWait( string[0] );
SendAndWait( string[1] );
SendAndWait( string[2] );
SendAndWait( string[3] );
//cout<<string;
PORTB &= ~(0x10); //CE = 0
wait(200);
}
void wait( unsigned long tmr_ms )
{
__tmr_ms=0; //global variable
MA_Start_TMR( 0, 1 ); //parameters: channel & reset on start
while(__tmr_ms !=tmr_ms); //wait
MA_Stop_TMR( 0 ); //no comment
}
SendAndWait ist eine SPI-Funktion und macht genau das, was der Name sagt.
Lesezeichen