[PIC] CS5532 ADC not initializing with my code

Status
Not open for further replies.

maheshdatta

Newbie level 1
Joined
Feb 3, 2015
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
8
Hi All,

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)

Please help.
 

Try it:

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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 data
    for (i = 0; i < 50; i++) {   //Keeping the /CS pin LOW
        Nop();
    }
 
  //  SPI1_CS = HIGH;
//    while (!SPI1STATbits.SPIRBF);   //Wait until receive is complete
    return 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;
}

 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…