Hello,
I am new to mbed and I am working on a project which uses a PIC as wireless link (MIWI) control unit and then i want to transfer the data the PIC recieves to an mbed which controls the rest of the system.
I am planning to use the SPI interface for this but I am not having much success. The PIC is the SPI master and the mbed is the slave.
I send a number of bytes from the PIC and have based my code for the mbed on the example in the handbook:
 Reply to a SPI master as slave
- include "mbed.h"
Serial pc(USBTX, USBRX);  tx, rx
SPISlave device(p5, p6, p7, p8);  mosi, miso, sclk, ssel
DigitalOut myled(LED1);
DigitalOut myled2(LED2);
int main() {
pc.printf("Hello World!\n");
    device.format (8,3);
    device.frequency(4000000);
    device.reply(0x05);               Prime SPI with first reply
    while(1) {
        if(device.receive()) {
              myled = 1;
            int v = device.read();
            pc.printf("\r Value is: %d \n", v);  
         device.reply(0x00);          Make this the next reply
        }
    }
} 
This work although not always reliably and recieves the first byte. However it does not recieve any of the other bytes I have sent. Is device.recieve return 1 after each byte has been recived or just at the start of a data stream. I have tried adding additional device.read lines in the if statement but that does not work.
If device.recieve does return 1 after each byte is recieved then something is wrong because the code inside the if statement is only run once when i send multiple bytes. Does there need to be a time delay between sending the bytes from the PIC?
Can anyone help me with this problem.
Thanks,
Tom
                    
                 
                
             
        
Hello,
I am new to mbed and I am working on a project which uses a PIC as wireless link (MIWI) control unit and then i want to transfer the data the PIC recieves to an mbed which controls the rest of the system.
I am planning to use the SPI interface for this but I am not having much success. The PIC is the SPI master and the mbed is the slave.
I send a number of bytes from the PIC and have based my code for the mbed on the example in the handbook:
Reply to a SPI master as slave
Serial pc(USBTX, USBRX); tx, rx SPISlave device(p5, p6, p7, p8); mosi, miso, sclk, ssel DigitalOut myled(LED1); DigitalOut myled2(LED2); int main() { pc.printf("Hello World!\n"); device.format (8,3); device.frequency(4000000); device.reply(0x05); Prime SPI with first reply while(1) { if(device.receive()) { myled = 1; int v = device.read(); pc.printf("\r Value is: %d \n", v);
device.reply(0x00); Make this the next reply } } }
This work although not always reliably and recieves the first byte. However it does not recieve any of the other bytes I have sent. Is device.recieve return 1 after each byte has been recived or just at the start of a data stream. I have tried adding additional device.read lines in the if statement but that does not work.
If device.recieve does return 1 after each byte is recieved then something is wrong because the code inside the if statement is only run once when i send multiple bytes. Does there need to be a time delay between sending the bytes from the PIC?
Can anyone help me with this problem.
Thanks,
Tom