![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
A
Fork of STM32-NRF-SPI_07112016 by
Diff: main.cpp
- Revision:
- 4:9df69d134631
- Parent:
- 3:b4887e2837ab
--- a/main.cpp Mon Nov 14 14:23:03 2016 +0000 +++ b/main.cpp Mon Nov 21 13:57:49 2016 +0000 @@ -4,66 +4,29 @@ //# MOSI P0_20 //# MISO P0_22 //# CS P0_7 -DigitalOut spi_cs(P0_7); -SPIClass SPI1(NRF_SPI1); +SPISlave device(p20,p22,p25,p7); Serial pc(USBTX, USBRX); -uint8_t i,izin=1; -uint8_t wt_buf[] = "DENEMEE"; -uint8_t rd_buf[7]; -uint32_t x=0; - - -uint8_t DATA_1[50]={0x07,0xdd,0xcc,0xee,0x15,0x23,0x56,0x11,0x33}; - - -void WriteBytes(uint16_t addr, uint8_t *pbuf, uint16_t len) -{ - uint16_t index; - spi_cs = 0; - wait_us(20); - for(index=0; index<len; index++) - { - SPI1.transfer(*pbuf); - pbuf++; - } - - wait_us(20); - spi_cs = 1; -} - -void ReadBytes(uint16_t addr, uint8_t *pbuf, uint16_t len) -{ - uint16_t index; - - spi_cs = 0; - wait_us(5); - for(index=0; index<len; index++) - { - *pbuf = SPI1.transfer(0x00); - pbuf++; - } - spi_cs = 1; -} - int main(void) { pc.baud(9600); - SPI1.begin(); //SPI1.begin(P0_6, P0_15, P0_29);//SCK, MOSI, MOSI pc.printf("SPI Demo Start\r\n"); - while(1) - { + + device.format(8,0); + device.frequency(4000000); // 4MHz + + uint8_t reply = 20; + device.reply(reply); // Bu satiri commentleyince çalışmıyor doğru, nedenini anlamadim. - WriteBytes(0, DATA_1, sizeof(DATA_1)); - for(i=0; i<sizeof(DATA_1); i++) - { - pc.printf("%02x",DATA_1[i]); - } - pc.printf(" %d \r\n",x); - - - wait(1); - - - } + pc.printf("======================================================\r\n"); + pc.printf("Startup Next reply will be %d\r\n", reply); + + while (1) { + if (device.receive()) + { + int valueFromMaster = device.read(); + device.reply(reply++); // Prime SPI with next reply + pc.printf("Received value from Master (%d) Next reply will be %d \r\n", valueFromMaster, reply); + } + } } \ No newline at end of file