I am trying to use CS5532 ADC for a checkweigher application. But in vain to initialize the ADC. I'm not able to get the "Reset Valid" (RV) bit of the ADC to be set.
I have attached my code which I am trying View attachment CS5532.rar.
Kindly suggest any possible solution.
ADC : Cirrus Logic CS5532 Circuit : is as per the schematic given in the datasheet in page no. 40 Microcontroller : PIC24FJ64GB106 running at 32MHz SPI : Tried with 250Khz, 500KHz, 1MHz (Max. SPI clock speed as per datasheet is 2MHz)
uint8_t Read_My_SPI1_Master_Char(void){uint8_t dummy, i;// SPI1_CS = LOW;if(SPI1STATbits.SPIRBF){// If our receive buffer is full
dummy = SPI1BUF;// Empty it...}
SPI1BUF =0;//Send the pulses to receive data by writing an invalid datafor(i =0; i <50; i++){//Keeping the /CS pin LOW
Nop();}// SPI1_CS = HIGH;// while (!SPI1STATbits.SPIRBF); //Wait until receive is completereturn SPI1BUF;}/******************************************************************************* * Function to perform Serial Port Initialization for the ADC * *******************************************************************************/uint32_t CS5532_Initialize(void){int loop_count =0;uint32_t reset;
SPI1_CS = LOW;for(loop_count =0; loop_count <51; loop_count++){
Write_My_SPI1_Master_Char(0xFF);}
Write_My_SPI1_Master_Char(0xFE);
SPI1_CS = HIGH;
__delay_ms(100);
reset = CS5532_Reset();return reset;}uint32_t CS5532_Reset(void){uint32_t reset;// Set RS in configuration register to "1" to reset CS5532.// First to write configuration register command
SPI1_CS = LOW;
Write_My_SPI1_Master_Char(CMD_WRITE_CFG_REG);// write data to configuration register, 32bits (4 bytes)
Write_My_SPI1_Master_Long(0x20000000);
SPI1_CS = HIGH;
__delay_ms(50);
SPI1_CS = LOW;//change RS in configuration register back to "0"// First to write configuration register command
Write_My_SPI1_Master_Char(CMD_WRITE_CFG_REG);// write data to configuration register, 32bits (4 bytes)
Write_My_SPI1_Master_Long(0x00000000);// Set RS to 0
SPI1_CS = HIGH;
Delay_ms(1);
SPI1_CS = LOW;//check if reset is successful(RV "1") or not.//read configuration register, send command first
Write_My_SPI1_Master_Char(CMD_READ_CFG_REG);// read 4-bytes from configuration register. MSB first.
reset = Read_My_SPI1_Master_Long();
SPI1_CS = HIGH;return reset;}