I-O DATA DEV2 / Mbed 2 deprecated nrf24_spi_test

Dependencies:   mbed

Committer:
hakusan270
Date:
Fri Dec 11 07:19:10 2020 +0000
Revision:
0:e35b82bee4e2
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hakusan270 0:e35b82bee4e2 1 #include "mbed.h"
hakusan270 0:e35b82bee4e2 2
hakusan270 0:e35b82bee4e2 3 /*
hakusan270 0:e35b82bee4e2 4 This basic example just shows how to read the ADC internal channels raw values.
hakusan270 0:e35b82bee4e2 5 Please look in the corresponding device reference manual for a complete
hakusan270 0:e35b82bee4e2 6 description of how to make a temperature sensor, VBat or Vref measurement.
hakusan270 0:e35b82bee4e2 7 */
hakusan270 0:e35b82bee4e2 8 DigitalIn mode(PC_13);
hakusan270 0:e35b82bee4e2 9 DigitalOut nRF_csn(D10 /*PB_6*/ );
hakusan270 0:e35b82bee4e2 10 DigitalOut nRF_ce(D9);
hakusan270 0:e35b82bee4e2 11 DigitalIn IRQ(D8);
hakusan270 0:e35b82bee4e2 12 //SPI nRF_spi(D4, D5, D3);// mosi, miso, sck,
hakusan270 0:e35b82bee4e2 13 SPI nRF_spi(PA_7, PA_6, PA_5);// mosi, miso, sck
hakusan270 0:e35b82bee4e2 14
hakusan270 0:e35b82bee4e2 15 int main()
hakusan270 0:e35b82bee4e2 16 {
hakusan270 0:e35b82bee4e2 17 printf("SPI TEST\r\n");
hakusan270 0:e35b82bee4e2 18 nRF_csn=1;//chip select disable
hakusan270 0:e35b82bee4e2 19 nRF_spi.frequency(4000000); // 1MHz SPI bus
hakusan270 0:e35b82bee4e2 20 nRF_spi.format(8,0); // 8bit normal porarity phase
hakusan270 0:e35b82bee4e2 21 wait(1.0);
hakusan270 0:e35b82bee4e2 22 int i;
hakusan270 0:e35b82bee4e2 23 int reg;
hakusan270 0:e35b82bee4e2 24 i=0;
hakusan270 0:e35b82bee4e2 25
hakusan270 0:e35b82bee4e2 26 while(1) {
hakusan270 0:e35b82bee4e2 27 nRF_csn=0;//chip select enable
hakusan270 0:e35b82bee4e2 28 nRF_spi.write(i);//register read command I=register number
hakusan270 0:e35b82bee4e2 29 reg = nRF_spi.write(i);//read reg value
hakusan270 0:e35b82bee4e2 30 nRF_csn=1; //chip select disable
hakusan270 0:e35b82bee4e2 31 printf("%d %02x \r\n",i,reg);
hakusan270 0:e35b82bee4e2 32 i++;
hakusan270 0:e35b82bee4e2 33 if (i>=32) i=0;
hakusan270 0:e35b82bee4e2 34 wait(0.1f);
hakusan270 0:e35b82bee4e2 35 }
hakusan270 0:e35b82bee4e2 36 }