Hi friends, I am working on 16 - channel data acquisition project, Silab C8051F310
- ADS1255 + external multiplexer.
ADC crystal is 7.643 MHz. SPI clock freq is 1.58 MHz
Hardware interface- CS --> permanently tied to ground 3 wire SPI (SCK, MOSI, MISO) DRDY as external interrupt source
When I debug the code by step by step it works most of the time. But in normal case it does not.
Whether my command sequence or delay between command is wrong. Or something else i am missing.
Source code
/** * @brief Write data to ADS1255 registers at specified address \a lbAddress * of specified length \a lbLength from pointer \a lpSource. * * @param lbLength - Specifies the number of Bytes to write * @param lbAddress - Specifies the destination ADS1255 register address * @param lpSource - Byte pointer to write data to ADS1255 * */ void Wr_ADS1255_Reg ( Byte lbLength, Byte lbAddress, Byte * lpSource ) { SELECT_ADS1255(); // Select ADS1255
SPI_Write ( 0x50 | lbAddress ); // Address with Write command SPI_Write ( lbLength - 1 ); // No of registers to write
do { SPI_Write ( *lpSource++ ); // Write the data } while ( --lbLength );
Wait_Clk ( 16 ); // Wait for 16 clock }
/** * @brief Read data from ADS1255 registers from specified address \a lbAddress * of specified length \a lbLength to pointer \a lpDest * * @param lbLength - Specifies the number of Bytes to read * @param lbAddress - Specifies the address of ADS1255 register * @param lpDest - Byte pointer to store data from ADS1255 * */ void Rd_ADS1255_Reg ( Byte lbLength, Byte lbAddress, Byte * lpDest ) { SELECT_ADS1255(); // Select ADS1255
SPI_Write ( lbAddress | 0x10 ); // Write Address with read command
SPI_Write ( lbLength - 1 ); // No of registers to read
Wait_Clk ( 80 ); // Wait for 80 clock
do { *lpDest++ = SPI_Read(); // Read data from ADS1255 } while ( --lbLength );
Wait_Clk ( 16 ); // Wait for 16 clock
}void Init_ADS1255 ( void) {
SELECT_ADS1255();
Send_SPI ( enWAKEUP ); // Wakeup the Ads1255. Wait_Clk ( 48 ); // Wait for 48 clocks
Send_SPI ( enRESET ); // Reset the ADS1255. Wait_Clk ( 48 ); // Wait for 48 clocks
// Read the registers to verify the communication Rd_ADS1255_Reg ( sizeof ( stRdReg ), 0, ( Byte * ) &stRdReg );
stWrReg.Status = 0x04; // Auto calibration is enabled stWrReg.MUX = 0x08; // Single ended channel 0 stWrReg.ADCON = 0; stWrReg.IO = 0xE0; // IO register stWrReg.DRate = 0xF0; // 30K SPS
Wr_ADS1255_Reg ( 5, 0, ( Byte * ) &stWrReg );
SPI_Write ( enSYNC ); // Syncronize the ADC
SPI_Write ( enWAKEUP ); // Wakeup the Adc
Rd_ADS1255_Reg ( sizeof ( stRdReg ), 0, ( Byte * ) &stRdReg );
SPI_Write ( enSELFCAL ); // perform Self calibration
}