Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 10 months ago.
SPI Slave class is not correct (cs has no effect)
HI, Looking at the class you understand that the SPISlave implementation doesn't make any special effort for taking ssel as a control for the whole communication. Even the clock .. since Slave dosen't decide what clock is used in the communication, the definitions shouldn't have a variable for the clock during the initialization. It is the master who decide what the clock is. I have a 2 Nucleo devices one master and the other is slave, but I have also a SD card connected to the same SPI. But the Slave Nucleo doesn't allow the SD card to work. If I keep the "reset" button pressed, at that time the SD-Card works . The slave SSEL doesn't stop the slave Nueclo from communicating to the Master. It dosen't affect the MISO,MOSI,CLK wich they should be in tri-state when the Nucleo doesn't have SSEL signal LOW. This class must be re-written. SSEL must take care of the MISO,MOSI & CLOCK pins and put them to TRI-State to isolate the module from the bus.
Code used for testing the slave
#include "mbed.h" //Code used inside the SLAVE - NUCLEO L476RG SPISlave slave(SPI_MOSI, SPI_MISO, SPI_SCK,PA_4 ); //DigitalIn gg(PA_4); Serial pc(USBTX, USBRX); int main() { // gg.mode(PullUp); slave.format(16,0); slave.frequency(100000); int v; slave.reply(0xBBBB); while(1) { pc.printf("try again ...\n"); if(slave.receive()) { v = slave.read(); if(v!=0) { pc.printf("v=%x\n\r", v); slave.reply(0xAAAA); } } wait(0.5); } }
Here is the code for the master
//Code used inside the MASTER- NUCLEO L476RG #include <mbed.h> Serial pc(USBTX, USBRX); SPI device(SPI_MOSI, SPI_MISO, SPI_SCK); DigitalOut cs(PC_8); int main() { int counter=0; sd.init(); cs=1; device.format(16,0); device.frequency(100000); while(1) { cs=0; pc.printf("%X\n\r", device.write(counter++)); cs=1; wait(1); } }