This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
art Number: ADS1248
Hi Team,
In my project I am using two RTDS with ADS1248 for temperature measurement. I am attaching two files with this. In SPI_Test1.c I wrote the SPI communication initialization and reading back from ADS1248 in the same main loop. Now to give an order to my main program I decided to rewrite the main code with all initialization routine as one group and signal readings in other. As a part of it I split my SPI_Test1.c as seen in SPI_Test2.c. I am using a 100 ohm fixed resistance across first channel AIN0-3 for ratiometric measurement. When ran the first code code I got an output code value equal '6217209' which is correct value. But when I ran the same code split into functions as seen in SPI_Test2.c some times I get nothing on first reading, sometimes I get the correct value and some times I get code equal to '8388607, which I think FSR. Why this happens?
Is it possible to keep START pin continuously HIGH so that the device goes on converting and read data at required times with RDATA command without monitoring DRDY pin?
Thank you,
Vineeth N
//***************************************************************************** // FILE NAME : C_138 SPI loop back Test.c // DATE : 20.05.2020 // AUTHORS : Vineeth N // DESCRIPTION : FOR TESTING SPI OF C_138 USING RTD // CONTROLLER CARD : Contoller 138 control Board //****************************************************************************** /* EXTERNAL CRYSTAL FREQUENCY 20MHz *******************************************************************************/ //----------------------------------------------------------------------------- // Include Header Files // ---------------------------------------------------------------------------- #include"F28x_Project.h" void main(void) { // Intiate system controls, GPIO pins, interrupt uint32_t r1 = 0x00000000; uint16_t r2 = 0x0000; uint32_t r3 = 0x0000000; InitSysCtrl(); InitGpio(); EALLOW; GpioCtrlRegs.GPAGMUX1.bit.GPIO9 = 1; GpioCtrlRegs.GPAMUX1.bit.GPIO9 = 3; // set Gpio pin 9 as SPI clock pin GpioCtrlRegs.GPAPUD.bit.GPIO9 = 0; // Pull up enable GpioCtrlRegs.GPAQSEL1.bit.GPIO9 = 3; // Qualifier Selection GpioCtrlRegs.GPAGMUX1.bit.GPIO8 = 1; GpioCtrlRegs.GPAMUX1.bit.GPIO8 = 3; // set Gpio pin 8 as SPI SIMO pin GpioCtrlRegs.GPAPUD.bit.GPIO8 = 0; // Pull up enable GpioCtrlRegs.GPAQSEL1.bit.GPIO8 = 3; // Qualifier Selection GpioCtrlRegs.GPAGMUX1.bit.GPIO10 = 1; GpioCtrlRegs.GPAMUX1.bit.GPIO10 = 3; // set Gpio pin 10 as SPI SOMI pin GpioCtrlRegs.GPAPUD.bit.GPIO10 = 0; // Pull up enable GpioCtrlRegs.GPAQSEL1.bit.GPIO10 = 3; // Qualifier Selection GpioCtrlRegs.GPAGMUX1.bit.GPIO14 = 0; GpioCtrlRegs.GPAMUX1.bit.GPIO14 = 0; // set Gpio pin 14 as GPIO output pin (CS/) GpioCtrlRegs.GPADIR.bit.GPIO14 = 1; // set direction as output GpioCtrlRegs.GPAGMUX1.bit.GPIO15 = 0; GpioCtrlRegs.GPAMUX1.bit.GPIO15 = 0; // set Gpio pin 15 as GPIO output pin (START) GpioCtrlRegs.GPADIR.bit.GPIO15 = 1; // set direction as output GpioCtrlRegs.GPBGMUX1.bit.GPIO34 = 0; GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0; // set Gpio pin 34 as GPIO output pin (ADC_RST) GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // set direction as output (ADC_RST) GpioCtrlRegs.GPAGMUX1.bit.GPIO6 = 0; GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 0; // set Gpio pin 6 as GPIO input pin (IRQ_3) GpioCtrlRegs.GPAPUD.bit.GPIO6 = 0; // Pull up enable EDIS; GpioDataRegs.GPASET.bit.GPIO14 = 1; // Clear CS/ pin to high GpioDataRegs.GPACLEAR.bit.GPIO15 = 1; // ADC_RST held low GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1; // START pin held low SpiaRegs.SPICCR.bit.SPISWRESET = 0; // clear software reset bit SpiaRegs.SPICTL.bit.MASTER_SLAVE = 1; // master mode selected SpiaRegs.SPICTL.bit.CLK_PHASE = 0; // clock phase selection SpiaRegs.SPICCR.bit.CLKPOLARITY = 0; // clock polarity SpiaRegs.SPIBRR.bit.SPI_BIT_RATE = 24; //(25MHz/25 = 1 MHz) SpiaRegs.SPICCR.bit.SPICHAR = 15; // character per transfer SpiaRegs.SPISTS.bit.INT_FLAG = 0; // clear interrupt flag SpiaRegs.SPISTS.bit.OVERRUN_FLAG = 0; // clear over run flag SpiaRegs.SPIPRI.bit.FREE = 1; SpiaRegs.SPICCR.bit.SPILBK = 0; // loop back enable SpiaRegs.SPICTL.bit.TALK = 1; // slave talk enabled SpiaRegs.SPICTL.bit.SPIINTENA = 0; // interrupt enable SpiaRegs.SPICCR.bit.SPISWRESET = 1; // software reset disabled GpioDataRegs.GPACLEAR.bit.GPIO14 = 1; // Clear CS/ pin to low GpioDataRegs.GPBSET.bit.GPIO34 = 1; // ADC_RST disabled GpioDataRegs.GPASET.bit.GPIO15 = 1; // Enable the device by setting START pin high SpiaRegs.SPITXBUF = 0xFF06; // Send the RESET command and wait for 0.6ms DELAY_US(600); SpiaRegs.SPITXBUF = 0x1640; // Send the SDATAC command and WREG Command 1st byte SpiaRegs.SPITXBUF = 0x030A; // WREG Command 2nd byte and MUX0 register value SpiaRegs.SPITXBUF = 0x0020; // VBIAS register value and MUX1 register value SpiaRegs.SPITXBUF = 0x404A; // SYS0 register and WREG 1st command byte SpiaRegs.SPITXBUF = 0x0105; // WREG 2nd command byte and IDAC0 register value SpiaRegs.SPITXBUF = 0x03FF; // IDAC1 register value and NOP command SpiaRegs.SPITXBUF = 0x2003; // RREG 1st and RREG 2nd byte SpiaRegs.SPITXBUF = 0xFFFF; // NOP commands SpiaRegs.SPITXBUF = 0xFFFF; // NOP commands SpiaRegs.SPITXBUF = 0x2A01; // RREG 1st and RREG 2nd byte SpiaRegs.SPITXBUF = 0xFF04; // NOP command and ADC SYNC DELAY_US(1); SpiaRegs.SPITXBUF = 0xFF12; // NOP and RDATA SpiaRegs.SPITXBUF = 0xFFFF; // NOP commands r1 = SpiaRegs.SPIRXBUF; // first 16 bits of conversion result MSB first SpiaRegs.SPITXBUF = 0xFFFF; // NOP and SLEEP command r2 = SpiaRegs.SPIRXBUF; // Second 8 bits of conversion result and remaining 8 bits of junk value r3 += (r1 << 8) + (r2 >> 8); SpiaRegs.SPITXBUF = 0x4000; // WREG Command 1st byte and WREG Command 2nd byte SpiaRegs.SPITXBUF = 0x254B; // MUX0 register value and WREG Command 1st byte SpiaRegs.SPITXBUF = 0x00AB; // WREG Command 2nd byte and IDAC1 register value SpiaRegs.SPITXBUF = 0x2000; // RREG 1st and RREG 2nd byte SpiaRegs.SPITXBUF = 0xFFFF; // NOP command SpiaRegs.SPITXBUF = 0x2B00; // RREG 1st and RREG 2nd byte SpiaRegs.SPITXBUF = 0xFF04; // NOP command and ADC SYNC DELAY_US(1); SpiaRegs.SPITXBUF = 0xFF12; // NOP and RDATA SpiaRegs.SPITXBUF = 0xFFFF; // NOP commands r1 = SpiaRegs.SPIRXBUF; // first 16 bits of conversion result MSB first SpiaRegs.SPITXBUF = 0xFF02; // NOP and SLEEP command r2 = SpiaRegs.SPIRXBUF; // Second 8 bits of conversion result and remaining 8 bits of junk value*/ r3 += (r1 << 8) + (r2 >> 8); while(1); }
//***************************************************************************** // FILE NAME : C_138 SPI loop back Test.c // DATE : 20.05.2020 // AUTHORS : Vineeth N // DESCRIPTION : FOR TESTING SPI OF C_138 USING RTD // CONTROLLER CARD : Contoller 138 control Board //****************************************************************************** /* EXTERNAL CRYSTAL FREQUENCY 20MHz *******************************************************************************/ //----------------------------------------------------------------------------- // Include Header Files // ---------------------------------------------------------------------------- #include"F28x_Project.h" void config(void); void spi(void); void read(void); uint32_t r1 = 0x00000000; uint16_t r2 = 0x0000; uint32_t r3 = 0x0000000; void main(void) { // Intiate system controls, GPIO pins, interrupt InitSysCtrl(); InitGpio(); EALLOW; GpioCtrlRegs.GPAGMUX1.bit.GPIO9 = 1; GpioCtrlRegs.GPAMUX1.bit.GPIO9 = 3; // set Gpio pin 9 as SPI clock pin GpioCtrlRegs.GPAPUD.bit.GPIO9 = 0; // Pull up enable GpioCtrlRegs.GPAQSEL1.bit.GPIO9 = 3; // Qualifier Selection GpioCtrlRegs.GPAGMUX1.bit.GPIO8 = 1; GpioCtrlRegs.GPAMUX1.bit.GPIO8 = 3; // set Gpio pin 8 as SPI SIMO pin GpioCtrlRegs.GPAPUD.bit.GPIO8 = 0; // Pull up enable GpioCtrlRegs.GPAQSEL1.bit.GPIO8 = 3; // Qualifier Selection GpioCtrlRegs.GPAGMUX1.bit.GPIO10 = 1; GpioCtrlRegs.GPAMUX1.bit.GPIO10 = 3; // set Gpio pin 10 as SPI SOMI pin GpioCtrlRegs.GPAPUD.bit.GPIO10 = 0; // Pull up enable GpioCtrlRegs.GPAQSEL1.bit.GPIO10 = 3; // Qualifier Selection GpioCtrlRegs.GPAGMUX1.bit.GPIO14 = 0; GpioCtrlRegs.GPAMUX1.bit.GPIO14 = 0; // set Gpio pin 14 as GPIO output pin (CS/) GpioCtrlRegs.GPADIR.bit.GPIO14 = 1; // set direction as output GpioCtrlRegs.GPAGMUX1.bit.GPIO15 = 0; GpioCtrlRegs.GPAMUX1.bit.GPIO15 = 0; // set Gpio pin 15 as GPIO output pin (START) GpioCtrlRegs.GPADIR.bit.GPIO15 = 1; // set direction as output GpioCtrlRegs.GPBGMUX1.bit.GPIO34 = 0; GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0; // set Gpio pin 34 as GPIO output pin (ADC_RST) GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // set direction as output (ADC_RST) GpioCtrlRegs.GPAGMUX1.bit.GPIO6 = 0; GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 0; // set Gpio pin 6 as GPIO input pin (IRQ_3) GpioCtrlRegs.GPAPUD.bit.GPIO6 = 0; // Pull up enable EDIS; config(); spi(); for(;;) { read(); } } void config(void) { GpioDataRegs.GPASET.bit.GPIO14 = 1; // Clear CS/ pin to high GpioDataRegs.GPACLEAR.bit.GPIO15 = 1; // ADC_RST held low GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1; // START pin held low SpiaRegs.SPICCR.bit.SPISWRESET = 0; // clear software reset bit SpiaRegs.SPICTL.bit.MASTER_SLAVE = 1; // master mode selected SpiaRegs.SPICTL.bit.CLK_PHASE = 0; // clock phase selection SpiaRegs.SPICCR.bit.CLKPOLARITY = 0; // clock polarity SpiaRegs.SPIBRR.bit.SPI_BIT_RATE = 24; //(25MHz/25 = 1 MHz) SpiaRegs.SPICCR.bit.SPICHAR = 15; // character per transfer SpiaRegs.SPISTS.bit.INT_FLAG = 0; // clear interrupt flag SpiaRegs.SPISTS.bit.OVERRUN_FLAG = 0; // clear over run flag SpiaRegs.SPIPRI.bit.FREE = 1; SpiaRegs.SPICCR.bit.SPILBK = 0; // loop back enable SpiaRegs.SPICTL.bit.TALK = 1; // slave talk enabled SpiaRegs.SPICTL.bit.SPIINTENA = 0; // interrupt enable SpiaRegs.SPICCR.bit.SPISWRESET = 1; // software reset disabled } void spi(void) { GpioDataRegs.GPBSET.bit.GPIO34 = 1; // ADC_RST disabled GpioDataRegs.GPASET.bit.GPIO15 = 1; // Enable the device by setting START pin high GpioDataRegs.GPACLEAR.bit.GPIO14 = 1; // Clear CS/ pin to low DELAY_US(3); SpiaRegs.SPITXBUF = 0xFF06; // Send the RESET command and wait for 0.6ms DELAY_US(600); SpiaRegs.SPITXBUF = 0x1640; // Send the SDATAC command and WREG Command 1st byte SpiaRegs.SPITXBUF = 0x030A; // WREG Command 2nd byte and MUX0 register value SpiaRegs.SPITXBUF = 0x0020; // VBIAS register value and MUX1 register value SpiaRegs.SPITXBUF = 0x404A; // SYS0 register and WREG 1st command byte SpiaRegs.SPITXBUF = 0x0105; // WREG 2nd command byte and IDAC0 register value SpiaRegs.SPITXBUF = 0x03FF; // IDAC1 register value and NOP command SpiaRegs.SPITXBUF = 0x2003; // RREG 1st and RREG 2nd byte SpiaRegs.SPITXBUF = 0xFFFF; // NOP commands SpiaRegs.SPITXBUF = 0xFFFF; // NOP commands SpiaRegs.SPITXBUF = 0xFF04; // NOP command and ADC SYNC DELAY_US(3); GpioDataRegs.GPASET.bit.GPIO14 = 1; // SET CS/ pin to HIGH } void read(void) { uint32_t rx3 = 0x0000000; r3 = 0x0000000; GpioDataRegs.GPACLEAR.bit.GPIO14 = 1; // Clear CS/ pin to low DELAY_US(3); SpiaRegs.SPITXBUF = 0xFF12; // NOP and RDATA SpiaRegs.SPITXBUF = 0xFFFF; // NOP commands r1 = SpiaRegs.SPIRXBUF; // first 16 bits of conversion result MSB first SpiaRegs.SPITXBUF = 0xFFFF; // NOP and SLEEP command r2 = SpiaRegs.SPIRXBUF; // Second 8 bits of conversion result and remaining 8 bits of junk value r3 += (r1 << 8) + (r2 >> 8); rx3 = r3; GpioDataRegs.GPASET.bit.GPIO14 = 1; // SET CS/ pin to HIGH }
Hi Vineeth,
This is acceptable, however it sounds like there may be a timing mismatch when you sometimes send SCLKs to retrieve data. If you do not monitor the DRDY pin, inevitably, there will be a small timing mismatch that leads to "drift" in terms of when you are taking the data. Eventually, this will lead to truncated samples - which it sounds like is what you are seeing. We typically recommend monitoring DRDY for this reason.
Hi Alex,
Thank you for your response. My aim is to read the result from ADC in every 20 ms interval. I have three other ADCs in my circuit. Total run time of the main loop is limited to 20 us. This is why I split up the ADC code to initialization part and signal read part, so that only signal reading part will be active in main loop. This was my idea. Considering this idea can you please give me a suggestion how I can accomplish this with monitoring DRDY pin.
I have a doubt that if I am not monitoring DRDY pin but still reading conversion results, it should give me last stored conversion result instead of some junk value, right?
I have tried pulsing the START pin with a 1 us positive pulse to obtain single conversion at a time. Since it is a single conversion I think the data on result register will not change. Am I reading this correct? If that is the case after pulsing START if I read result I should get proper value. With this method also I am getting same wrong values around around 8388607.
How to do single conversions with thios ADC?. I can't do it with SLEEP and WAKEUP commands because I can't keep CS/ low all the time, Since I have other SPI ADCs .
Thank you,
Vineeth N
Hi Vineeth,
If you take a look at the command table Table 19. SPI Commands for reference. Upon power-up and initialization, I would recommend issuing an SDATAC command in order to stop continuous conversions. Then, you can simply use the RDATA command to read data once from each ADC every time you loop. This way you can leave the START pin HIGH.
Yes, however if you are in the middle of reading a result, then a new conversion becomes ready, the read result will be corrupted as it will be composed of two different read results.
You must wait at least 3tclk after pulling START high to begin reading - it is possible that the timing is being violated.