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.
Hello,
I am trying to write and read from the ADS1263 SPI using the STM32F437 processor but the data I get on the DOUT/DRDY is always 0.
The SPI setting I use is:
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
The SCLK frequency is 6 MHz (48 M / 8).
To read a register I use the following code:
adc_in[0] = ADS1263_RREG_CMD + REGX // REGX = 0 .. 26
adc_in[1] = 0;
SPI_ADC_ReadReg(adc_in, adc_out);
The function SPI_ADC_ReadReg look like this:
void SPI_ADC_ReadReg(u8 u8 *adc_in, u8 *adc_out)
{
/* Loop while DR register in not emplty */
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);
/* Select the ADC: Chip Select low */
SPI_ADC_CS1_LOW;
for (int i=0; i<3+adc_in[1]; i++)
{
/* Send Half Word through the SPI2 peripheral */
SPI_I2S_SendData(SPI1, adc_in[i]);
/* Loop while DR register in not emplty */
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
}
/* Wait to receive a byte */
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
/* Loop while DR register in not emplty */
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);
/* Return the Half Word read from the SPI bus */
adc_out[0] = SPI_I2S_ReceiveData(SPI1);
/* Deselect the ADC: Chip Select low */
SPI_ADC_CS1_HIGH;
}
On a logic scope all the signals - CS, SCLK and MOSI look OK. Only DOUT/DRDY is stuck at 0.
Can you tell me what I'm missing?
Thanks
Hi Joseph
So I finally got the ReadReg function to work.
The problem was: You have to read the first 2 bytes and discard them. So for anyone who is interested here are the settings and function that work for reading 1 register :
Setting:
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; //SPI_CPHA_2Edge
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8; //If using SPI_BaudRatePrescaler_4, will create garbage data im M25P128
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
Function:
void SPI_ADC_ReadReg(u8 *adc_in, u8 *adc_out)
{
/* Loop while DR register in not emplty */
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);
/* Select the ADC: Chip Select low */
SPI_ADC_CS1_LOW;
for (int i=0; i<3]; i++)
{
/* Send Half Word through the SPI2 peripheral */
SPI_I2S_SendData(SPI1, adc_in[i]);
/* Loop while DR register in not emplty */
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
/* Wait to receive a byte */
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
/* Return the Half Word read from the SPI bus */
adc_out[0] = SPI_I2S_ReceiveData(SPI1);
}
}
Thanks again