Hi
i wrote a small test programm, before porting my whole stack to my mbed. I tried it with the hardware SPI class first, it didn't work so i wrote a Software SPI for testing.
#include "mbed.h"
DigitalOut sel(p10);
DigitalIn irq(p9);
DigitalOut sdi(p11);
DigitalIn sdo(p12);
DigitalOut sck(p13);
void InitRFModule()
{
sel.write(1);
sdi.write(1);
sck.write(0);
wait(1);
RFWrite(0x80D8);
RFWrite(0x8201);
RFWrite(0xA640);
RFWrite(0xC647);
RFWrite(0x94A0);
RFWrite(0xC2AC);
RFWrite(0xCA81);
RFWrite(0xCED4);
RFWrite(0xC483);
RFWrite(0x9850);
RFWrite(0xCC77);
RFWrite(0xE000);
RFWrite(0xC800);
RFWrite(0xC040);
wait(1);
}
short RFWrite(short b)
{
char i;
short temp = 0;
sck.write(0);
sel.write(0);
for(i = 0; i < 16; i++)
{
if(b & 0x8000)
{
sdi.write(1);
}
else
{
sdi.write(0);
}
sck.write(1);
temp <<= 1;
if(sdo.read())
{
temp |= 0x0001;
}
sck.write(0);
b <<= 1;
}
sel.write(1);
return temp;
}
void RFSend(char b)
{
while(irq.read());
RFWrite(0xB800 + b);
}
void SEND()
{
int i;
char checksum;
RFWrite(0x0000);
RFWrite(0x8239);
checksum = 0;
RFSend(0xAA); //Preamble
RFSend(0xAA);
RFSend(0xAA);
RFSend(0x2D); //Sync HI
RFSend(0xD4); //Sync LO
for(i = 0; i < 16; i++)
{
RFSend(0x20 + i);
checksum += (0x20 + i);
}
RFSend(checksum);
RFSend(0xAA);
RFSend(0xAA);
RFSend(0xAA);
RFWrite(0x8201);
}
int main()
{
InitRFModule();
for(;;)
{
wait(1);
SEND();
}
}
it worked well, and my receiver got all the data.
So now im trying to use the hardware SPI class. I added following code
SPI spi(p11, p12, p13);
//modified my RFWrite
short RFWrite(short b)
{
short temp = 0;
sel.write(0);
temp = spi.write( b );
sel.write(1);
return temp;
}
int main()
{
//Added SPI Init to main method
spi.format( 8, 0 );
spi.frequency( 125000 );
//...
}
bot the RF Module doesn't send anything, it doesn't even get initalized.
I cant find my mistake, mode 0 should be right (isn't it?).
can anyone help me out?
dominik
Hi
i wrote a small test programm, before porting my whole stack to my mbed. I tried it with the hardware SPI class first, it didn't work so i wrote a Software SPI for testing.
So now im trying to use the hardware SPI class. I added following code
I cant find my mistake, mode 0 should be right (isn't it?).
can anyone help me out?
dominik