test code for SPI communications with any board
Diff: main.cpp
- Revision:
- 16:8f8adc5f8f0a
- Parent:
- 15:d3c93f01a02b
- Child:
- 17:f200f87b4087
--- a/main.cpp Mon Jan 31 20:43:05 2022 +0000 +++ b/main.cpp Mon Jan 31 21:44:38 2022 +0000 @@ -25,7 +25,8 @@ int spi_enabled = 0; InterruptIn cs(PA_4); -SPISlave spi(PA_7, PA_6, PA_5, PA_4); +SPISlave *spi; +//SPISlave spi(PA_7, PA_6, PA_5, PA_4); uint32_t xor_checksum(uint32_t* data, size_t len) { @@ -80,9 +81,9 @@ int bytecount = 0; //spi.reply(tx_buff[0]); while (cs==0){ - if(spi.receive()) { - rx_buff[bytecount] = spi.read(); - if (bytecount<TX_LEN) {spi.reply(tx_buff[bytecount]);} + if(spi->receive()) { + rx_buff[bytecount] = spi->read(); + if (bytecount<TX_LEN) {spi->reply(tx_buff[bytecount]);} bytecount++; } } @@ -122,9 +123,10 @@ // Wait for CS to not be low, then enable SPI if(!spi_enabled){ while((spi_enabled==0) && (cs.read()==0)){pc.printf("waiting for CS Pin\n"); wait_us(10);} - spi.format(8, 0); - spi.frequency(500000); - spi.reply(0x0); + spi = new SPISlave(PA_7, PA_6, PA_5, PA_4); + spi->format(8, 0); + spi->frequency(500000); + spi->reply(0x0); spi_enabled = 1; cs.fall(&spi_isr); pc.printf("SPI ENABLED AND READY\n");