Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

Problem while reading the data from ADS1259

$
0
0

Hi

I am using ADS1259 ADC in my product. I am using STM32F407 micro controller.

I am able to send commands/data to ADC but i am not able to receive any data from ADC. 
Dataoutput line of the ADC always stays at low.

For reading a register data i am sending opcode,register address, Number of registers. After that i am sending dummy byte 0xff to generate clock for reading data. Am i followig correct way or not?

Can any one help me to resolve the issue:

/****************************************************************/

/* define GPIO OF serial peripheral interface for ADC1_ADS1259 */

/****************************************************************/

#define ADC1_ADS1259_DR_PIN GPIO_Pin_3 //Data Ready

#define ADC1_ADS1259_DR_GPIO_PORT GPIOE //Data Ready

#define ADC1_ADS1259_DR_GPIO_CLK RCC_AHB1Periph_GPIOE

#define ADC1_ADS1259_DR_SOURCE GPIO_PinSource3

#define ADC1_ADS1259_START_PIN GPIO_Pin_4 //Start Analog to digital Conversion

#define ADC1_ADS1259_START_GPIO_PORT GPIOE

#define ADC1_ADS1259_START_GPIO_CLK RCC_AHB1Periph_GPIOE

#define ADC1_ADS1259_START_SOURCE GPIO_PinSource4

#define ADC1_ADS1259_SPI SPI2

#define ADC1_ADS1259_SPI_CLK RCC_APB1Periph_SPI2

#define ADC1_ADS1259_SPI_CLK_INIT RCC_APB1PeriphClockCmd

#define ADC1_ADS1259_SPI_SCK_PIN GPIO_Pin_1

#define ADC1_ADS1259_SPI_SCK_GPIO_PORT GPIOI

#define ADC1_ADS1259_SPI_SCK_GPIO_CLK RCC_AHB1Periph_GPIOI

#define ADC1_ADS1259_SPI_SCK_SOURCE GPIO_PinSource1

#define ADC1_ADS1259_SPI_SCK_AF GPIO_AF_SPI2

#define ADC1_ADS1259_SPI_MISO_PIN GPIO_Pin_2

#define ADC1_ADS1259_SPI_MISO_GPIO_PORT GPIOI

#define ADC1_ADS1259_SPI_MISO_GPIO_CLK RCC_AHB1Periph_GPIOI

#define ADC1_ADS1259_SPI_MISO_SOURCE GPIO_PinSource2

#define ADC1_ADS1259_SPI_MISO_AF GPIO_AF_SPI2

#define ADC1_ADS1259_SPI_MOSI_PIN GPIO_Pin_3

#define ADC1_ADS1259_SPI_MOSI_GPIO_PORT GPIOI

#define ADC1_ADS1259_SPI_MOSI_GPIO_CLK RCC_AHB1Periph_GPIOI

#define ADC1_ADS1259_SPI_MOSI_SOURCE GPIO_PinSource3

#define ADC1_ADS1259_SPI_MOSI_AF GPIO_AF_SPI2

#define ADC1_ADS1259_SPI_CS_PIN GPIO_Pin_9

#define ADC1_ADS1259_SPI_CS_GPIO_PORT GPIOC

#define ADC1_ADS1259_SPI_CS_GPIO_CLK RCC_AHB1Periph_GPIOC

#define ADC1_ADS1259_SPI_CS_SOURCE GPIO_PinSource0

#define ADC1_ADS1259_RESET_PIN GPIO_Pin_13 //Data Ready

#define ADC1_ADS1259_RESET_GPIO_PORT GPIOC //Data Ready

#define ADC1_ADS1259_SPI_RESET_GPIO_CLK RCC_AHB1Periph_GPIOC

#define ADC1_ADS1259_SPI_RESET_SOURCE GPIO_PinSource13

/* Exported macro ------------------------------------------------------------*/

/* Select ADS1259: Chip Select pin low */

#define ADC1_ADS1259_CS_LOW() GPIO_ResetBits( ADC1_ADS1259_SPI_CS_GPIO_PORT , ADC1_ADS1259_SPI_CS_PIN )

/* Deselect sFLASH: Chip Select pin high */

#define ADC1_ADS1259_CS_HIGH() GPIO_SetBits(ADC1_ADS1259_SPI_CS_GPIO_PORT , ADC1_ADS1259_SPI_CS_PIN )

/* ADS1259: Start pin low */

#define ADC1_ADS1259_START_LOW() GPIO_ResetBits( ADC1_ADS1259_START_GPIO_PORT , ADC1_ADS1259_START_PIN )

/* ADS1259 Start pin high */

#define ADC1_ADS1259_START_HIGH() GPIO_SetBits(ADC1_ADS1259_START_GPIO_PORT , ADC1_ADS1259_START_PIN )

/* ADS1259: RESET pin low */

#define ADC1_ADS1259_RESET_LOW() GPIO_ResetBits( ADC1_ADS1259_RESET_GPIO_PORT , ADC1_ADS1259_RESET_PIN )

/* ADS1259 RESET pin high */

#define ADC1_ADS1259_RESET_HIGH() GPIO_SetBits(ADC1_ADS1259_RESET_GPIO_PORT , ADC1_ADS1259_RESET_PIN )

extern void fnDelayInMilliSeconds(uint32_t ulDelayInMilliSeconds);

void ADC1_ADS1259_LowLevel_Init(void)

{

GPIO_InitTypeDef GPIO_InitStructure;

//Enable the SPI clock

RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2,ENABLE);

RCC_AHB1PeriphClockCmd(ADC1_ADS1259_SPI_SCK_GPIO_CLK | ADC1_ADS1259_SPI_MISO_GPIO_CLK |

ADC1_ADS1259_SPI_MOSI_GPIO_CLK | ADC1_ADS1259_SPI_CS_GPIO_CLK|ADC1_ADS1259_DR_PIN|

ADC1_ADS1259_START_PIN , DISABLE);

// Enable GPIO clocks

RCC_AHB1PeriphClockCmd(ADC1_ADS1259_SPI_SCK_GPIO_CLK | ADC1_ADS1259_SPI_MISO_GPIO_CLK |

ADC1_ADS1259_SPI_MOSI_GPIO_CLK | ADC1_ADS1259_SPI_CS_GPIO_CLK|ADC1_ADS1259_DR_PIN|

ADC1_ADS1259_START_PIN|ADC1_ADS1259_RESET_PIN, ENABLE);

/*!< Connect SPI pins to AF5 */

//Need to check these Items

GPIO_PinAFConfig(ADC1_ADS1259_SPI_SCK_GPIO_PORT,ADC1_ADS1259_SPI_SCK_SOURCE, ADC1_ADS1259_SPI_SCK_AF);

GPIO_PinAFConfig(ADC1_ADS1259_SPI_MISO_GPIO_PORT,ADC1_ADS1259_SPI_MISO_SOURCE,ADC1_ADS1259_SPI_MISO_AF);

GPIO_PinAFConfig(ADC1_ADS1259_SPI_MOSI_GPIO_PORT, ADC1_ADS1259_SPI_MOSI_SOURCE,ADC1_ADS1259_SPI_MOSI_AF);

// Check Completed

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;

/*!< SPI SCK pin configuration */

GPIO_InitStructure.GPIO_Pin = ADC1_ADS1259_SPI_SCK_PIN;

GPIO_Init(ADC1_ADS1259_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);

/*!< SPI MOSI pin configuration */

GPIO_InitStructure.GPIO_Pin = ADC1_ADS1259_SPI_MOSI_PIN;

GPIO_Init(ADC1_ADS1259_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);

/*!< SPI MISO pin configuration */

GPIO_InitStructure.GPIO_Pin = ADC1_ADS1259_SPI_MISO_PIN;

GPIO_Init(ADC1_ADS1259_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);

/*!< Configure ADS1259 CS pin in output pushpull mode ********************/

GPIO_InitStructure.GPIO_Pin = ADC1_ADS1259_SPI_CS_PIN;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_Init(ADC1_ADS1259_SPI_CS_GPIO_PORT, &GPIO_InitStructure);

/*!< Configure ADS1259 Start pin in output pushpull mode ********************/

GPIO_InitStructure.GPIO_Pin = ADC1_ADS1259_START_PIN;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_Init(ADC1_ADS1259_START_GPIO_PORT, &GPIO_InitStructure);

/*!< ADS1259 DR pin configuration */

GPIO_InitStructure.GPIO_Pin = ADC1_ADS1259_DR_PIN;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//GPIO_Mode_IN_FLOATING;

GPIO_Init(ADC1_ADS1259_DR_GPIO_PORT, &GPIO_InitStructure);

/*!< ADS1259 Reset pin configuration */

GPIO_InitStructure.GPIO_Pin = ADC1_ADS1259_RESET_PIN;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_Init(ADC1_ADS1259_RESET_GPIO_PORT, &GPIO_InitStructure);

ADC1_ADS1259_RESET_HIGH();

}

void init_SPI(void)

{

GPIO_InitTypeDef GPIO_InitStructure;

SPI_InitTypeDef SPI_InitStructure;

ADC1_ADS1259_LowLevel_Init();

//Make Reset Pin High

GPIO_SetBits(GPIOC , GPIO_Pin_13 );

//Make Start Pin Low

GPIO_ResetBits( GPIOE , GPIO_Pin_4 );

//Make Chip Select Pin High

GPIO_SetBits(GPIOC , GPIO_Pin_9 );

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_16;

SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;

SPI_InitStructure.SPI_CRCPolynomial = 7;

SPI_Init(SPI2, &SPI_InitStructure);

SPI_I2S_ClearFlag(SPI2, SPI_I2S_FLAG_TXE);

SPI_I2S_ClearFlag(SPI2, SPI_I2S_FLAG_RXNE);

// Enable the SPI2 Interface

SPI_Cmd(SPI2, ENABLE);

}

/**

* @brief Sends a byte through the SPI interface and return the byte received

* from the SPI bus.

* @param byte: byte to send.

* @retval The value of the received byte.

*/

uint8_t SendByteOverSPI(uint8_t byte)

{

/*!< Loop while DR register in not emplty */

while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);

/*!< Send byte through the SPI1 peripheral */

SPI_I2S_SendData(SPI2, byte);

/*!< Wait to receive a byte */

while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);

//while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);

/*!< Return the byte read from the SPI bus */

return SPI_I2S_ReceiveData(SPI2);

}

uint8_t InitADS1259(void)

{

//Writing to the registers

SendByteOverSPI(0X11); //Stop Read continuos mode

SendByteOverSPI(0x0A); //STOP Command

SendByteOverSPI(0x06); //Reset Command

fnDelayInMilliSeconds(50);

SendByteOverSPI(0x11);

SendByteOverSPI(0x0A);

SendByteOverSPI(0X40);//Write COmmand starting address 0

fnDelayInMilliSeconds(10);

SendByteOverSPI(0x08);//Number registers to be write are 9

fnDelayInMilliSeconds(10);

SendByteOverSPI(0x80);//Config 0 :Internal Bias and SPI timeout

fnDelayInMilliSeconds(20);

SendByteOverSPI(0x07);//Config 1

fnDelayInMilliSeconds(20);

SendByteOverSPI(0x12); //Pulse COntrol Mode and 50 SPS

fnDelayInMilliSeconds(20);

SendByteOverSPI(0X00);//Offset register

fnDelayInMilliSeconds(20);

SendByteOverSPI(0X00);

fnDelayInMilliSeconds(20);

SendByteOverSPI(0X00);//Full scale calibration

fnDelayInMilliSeconds(20);

SendByteOverSPI(0X00);

fnDelayInMilliSeconds(20);

SendByteOverSPI(0X40);

fnDelayInMilliSeconds(20);

}

void ReadADS1259Registers(void)

{

uint8_t ucReadValue;

char cStringBuffer[200];

SendByteOverSPI(0X20);//Write COmmand starting address 0

SendByteOverSPI(0x08);//Number registers to be write are 9

ucReadValue=SendByteOverSPI(0XFF);

sprintf( cStringBuffer,"config0 =%d\n\r",ucReadValue);

PutString(APPLICATION_PORT,cStringBuffer,1);

ucReadValue=SendByteOverSPI(0XFF);

sprintf( cStringBuffer,"config1 =%d\n\r",ucReadValue);

PutString(APPLICATION_PORT,cStringBuffer,1);

ucReadValue=SendByteOverSPI(0XFF);

sprintf( cStringBuffer,"config2 =%d\n\r",ucReadValue);

PutString(APPLICATION_PORT,cStringBuffer,1);

ucReadValue=SendByteOverSPI(0XFF);

sprintf( cStringBuffer,"OFFSET0 =%d\n\r",ucReadValue);

PutString(APPLICATION_PORT,cStringBuffer,1);

ucReadValue=SendByteOverSPI(0XFF);

sprintf( cStringBuffer,"OFFSET1 =%d\n\r",ucReadValue);

PutString(APPLICATION_PORT,cStringBuffer,1);

ucReadValue=SendByteOverSPI(0XFF);

sprintf( cStringBuffer,"OFFSET2 =%d\n\r",ucReadValue);

PutString(APPLICATION_PORT,cStringBuffer,1);

ucReadValue=SendByteOverSPI(0XFF);

sprintf( cStringBuffer,"FUllScale0 =%d\n\r",ucReadValue);

PutString(APPLICATION_PORT,cStringBuffer,1);

ucReadValue=SendByteOverSPI(0XFF);

sprintf( cStringBuffer,"FUllScale1 =%d\n\r",ucReadValue);

PutString(APPLICATION_PORT,cStringBuffer,1);

ucReadValue=SendByteOverSPI(0XFF);

sprintf( cStringBuffer,"FUllScale2 =%d\n\r",ucReadValue);

PutString(APPLICATION_PORT,cStringBuffer,1);

}

int main(void)

{

uint8_t ucRetValue;

InitializeSysTickTimer();

init_UART(APPLICATION_PORT);

init_SPI();

GPIO_ResetBits(GPIOC , GPIO_Pin_13 );

fnDelayInMilliSeconds(20);

GPIO_SetBits(GPIOC , GPIO_Pin_13 );

GPIO_ResetBits(GPIOC , GPIO_Pin_9 );

InitADS1259();

//ReadADS1259Registers();

while(1)

{

//ucRetValue=SendByteOverSPI(0xAA);

ReadADS1259Registers();

}

 


Viewing all articles
Browse latest Browse all 262198

Trending Articles