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.
7 years, 4 months ago.
How to read data through SPI on Nucleo-F411RE board
Hello,
Basically, I want to interface ADS1292R with the Nucleo-F411RE board. I want to test reading and writing operation of this IC. So I wrote some code but it's not working. Actually, I have doubt on SPI configuration. Testing Done: 1) I am not able to see any MOSI, SCLK signal data on DSO at the time of write operation. 2) I didn't see any MISO data on DSO at the time of reading operation but I saw SCLK. Can someone help me how to do that?
Please find the source code.
#include "mbed.h" #include <SPI.h> // Register Read Commands #define RREG 0x20; //Read n nnnn registers starting at address r rrrr //first byte 001r rrrr (2xh)(2) - second byte 000n nnnn(2) #define WREG 0x40; //Write n nnnn registers starting at address r rrrr //first byte 010r rrrr (2xh)(2) - second byte 000n nnnn(2) #define START 0x08 //Start/restart (synchronize) conversions #define STOP 0x0A //Stop conversion #define RDATAC 0x10 //Enable Read Data Continuous mode. //This mode is the default mode at power-up. #define SDATAC 0x11 //Stop Read Data Continuously mode #define RDATA 0x12 //Read data by command; supports multiple read back. #define HIGH (1) #define LOW (0) #define PIN_PWDN (1) #define PIN_START (2) #define PIN_DRDY (3) #define PIN_CS (4) //register address #define ADS1292_REG_ID 0x00 #define ADS1292_REG_CONFIG2 0x02 DigitalOut ADS1292_PWDN_PIN(PB_5); //pin PD_4 used for power down of the ADS1292 DigitalOut ADS1292_START_PIN(PB_4); // pin PD_5 used for Start of the ADS1292 DigitalOut ADS1292_CS_PIN(PA_8); //pin PD_7 used for Chip select of the ADS1292 DigitalIn ADS1292_DRDY_PIN(PB_10); //pin PD_6 used for Data ready input of the ADS1292 SPI device(SPI_MOSI, SPI_MISO, SPI_SCK); Serial pc(SERIAL_TX, SERIAL_RX); void digitalWrite(int pin_in, int status_in){ switch(pin_in){ case PIN_PWDN: ADS1292_PWDN_PIN = status_in; break; case PIN_START: ADS1292_START_PIN = status_in; break; case PIN_CS: ADS1292_CS_PIN = status_in; break; default : break; }} void Reg_Write (unsigned char READ_WRITE_ADDRESS, unsigned char DATA) { pc.printf("In Function Write_Data()\n\r"); switch (READ_WRITE_ADDRESS) { case 1: DATA = DATA & 0x87; break; case 2: DATA = DATA & 0xFB; DATA |= 0x80; break; default: break; } // now combine the register address and the command into one byte: unsigned char dataToSend = READ_WRITE_ADDRESS | WREG; digitalWrite(PIN_CS, LOW); wait_us(2); digitalWrite(PIN_CS, HIGH); wait_us(2); digitalWrite(PIN_CS, LOW); // take the chip select low to select the device: wait_us(2); device.write(dataToSend); //Send register location device.write(0x00); //number of register to wr device.write(DATA); //Send value to record into register wait_us(2); digitalWrite(PIN_CS, HIGH); // take the chip select high to de-select: } void Reg_Read (unsigned char READ_WRITE_ADDRESS){ unsigned char dataToSend = READ_WRITE_ADDRESS | RREG; digitalWrite(PIN_CS, LOW); wait_us(2); digitalWrite(PIN_CS, HIGH); wait_us(2); digitalWrite(PIN_CS, LOW); // take the chip select low to select the device: wait_us(2); device.write(dataToSend); //Send register location device.write(0x00); //number of register to wr unsigned char Value = device.write(0x00); //Send value to record into register pc.printf("Data read : %x\n\r",Value); wait_us(2); digitalWrite(PIN_CS, HIGH); // take the chip select high to de-select: } void SPI_Init(void){ pc.printf("In Function SPI_Init()\n\r"); digitalWrite(PIN_CS, HIGH); device.format(8,1); device.frequency(1000000); digitalWrite(PIN_CS, LOW); } int main() { int i = 0; pc.baud(115200); pc.printf("In Function main()\n\r"); SPI_Init(); wait(5); while(1) { i++; Reg_Write(ADS1292_REG_CONFIG2, 0b11111111); //Lead-off comp off, test signal disabled 0b10100000 wait_us(10); Reg_Read(ADS1292_REG_CONFIG2); if(i == 10) while(1); wait(5); } }
Result: In Function main() In Function SPI_Init() In Function Write_Data() Data read : 0 In Function Write_Data() Data read : 0
1 Answer
7 years, 4 months ago.
Code looks *ok* but I have a couple of questions: Are you using these pins? SPI_MOSI = PA_7, SPI_MISO = PA_6, SPI_SCK = PA_5, SPI_CS = PB_6,
The frequency of the external clock fCLK on the AD1292 does matter. What is it?
Have you tried slower SPI frequencies and increasing the delay time between CS->LOW and CS->HIGH?
I am using SPI_MOSI = PA_7, SPI_MISO = PA_6, SPI_SCK = PA_5 but for SPI_CS = PA_8. So is there any problem to use this pin.
As per my understanding, I am not using external clock frequency. Basically, I am using ready-made hardware which is provided by "ADS1292r breakout".
I didn't try slower SPI frequencies.
Thank you very much for your reply Bill Bellis, Let me know if you have any more questions. Looking forward to the same issue.
posted by 20 Jun 2017
Updated my reply
posted by Bill Bellis 20 Jun 2017