#define ADDRESS_LENGTH 5
char test[5];
void SPI_Send(char data)
{
char i;
for(i = 0 ; i < 8 ; i++)
{
MOSI = data.7;
SCK = 1;
SCK = 0;
data <<= 1;
}
}
// output command and get STATUS value from SPI
char SPI_Send_Read_cmd(char command)
{
uns8 i;
uns8 status,data;
data = command;
for(i = 0 ; i < 8 ; i++)
{
status << =1;
MOSI = data.7;
SCK = 1;
status.0 = MISO;
SCK = 0;
data <<= 1;
}
return status;
}
//Send N bytes from buf into SPI
char SPI_Send_N (char *buf, char Length)
{
char len =0;
while (Length != 0)
{
SPI_Send(*buf++);
Length–;
len++;
}
return len;
}
char readRegister_Len(char command, char * buffer, char len)
{
char status;
CE = 0; // ensure chip is disabled
CSN = 0; // acivate chip select
status = SPI_Send_Read_cmd(command); // write command
SPI_Read_N(buffer,len); // read registers
CSN = 1; // disable chip select
return status;
}
Following is application
writeRegister_addr(RX_ADDR_P1, Client_Address);
/*
Perform a simple read to make sure that memory is being
correctly written.
*/
readRegister_Len(RX_ADDR_P1, &test[0],ADDRESS_LENGTH);
/*
Will return NO_POWER if the read RX1 address does not match
the address written, meaning that there’s no power to the
module.
*/
if(test[0] != Client_Address[0] || test[1] != Client_Address[1] || test[2] != Client_Address[2]
|| test[3] != Client_Address[3] || test[4] != Client_Address[4]){
return 0;
}
i find the value of test always not equal to the value of Client_Address,why??