I have a problem reading a PT100 probe through the ADS1243.
writing and reading the registry is just but when i set MUX register 0x66 (AIN6 positive and Negative channel select) I expect to receive 0 but I receive 8387908.
as anyone else experienced problems like this? And if so how did you solve them?
thak you
/**************************************************************************//**
* @brief spi_init used to read ADS1243 device
*****************************************************************************/
void spi_ads1243_init(void)
{
u16 i;
gpio_mux_and_ads_init();
for (i = 0; i < 0xfffe; i++); // Delay for XTAL stabilization
//BCSCTL1 |= DIVA_3; // ACLK= LFXT1CLK/8 = 4096Hz
DCOCTL = 0x9E; //4.9 MHZ
BCSCTL1 = 0xBB;
P1DIR |= 0x10; // P1.4 output
P1SEL |= 0x10; // P1.4 SMCLK output
UCB1CTL1 |= UCSWRST; // Reset USCI0 Module
P5SEL |= 0x0E; //P5.1 P5.2 P5.3 for
UCB1CTL0 |= UCMST+UCSYNC+UCMSB+UCCKPH+UCCKPL; //UCCKPH UCCKPL+
UCB1CTL1 = 0xC0;
UCB1STAT = 0; // clear all error bits
// UCB1BR0 = 40; // MCLK/4 for baud rate
// UCB1BR1 = 0x00;
UCB1BR0 = 0x6b & 0xff; // SPICLK = SMCLK/40
UCB1BR1 = 0x00;
// MCLK/2 for baud rate
UCB1CTL1 &= ~UCSWRST; /* Reset USCI0 Module */
}
/**************************************************************************//**
* @brief read data from ADS1243
*****************************************************************************/
u32 ADS1243ReadData(u16 fWaitForDataReady)
{
u32 Data;
Data = 0;
u8 i=0;
while((i & 0x80)!= 0x80){
tosc++;
ADS1243AssertCS(1);
spi_ads1243_send_byte(0x12); // register
Pause(10 * tosc); // delay 20 µs
spi_ads1243_send_byte(0);
Pause(10 * tosc); // delay 20 µs
//delay_ticks(2);
i = spi_ads1243_recv_byte();
Pause(10 * tosc);
ADS1243AssertCS(0);
}
// assert CS to start transfer
ADS1243AssertCS(1);
// send the command byte
spi_ads1243_send_byte(ADS1243_CMD_RDATA);
//delay_ticks(1); // wait 200ms
Pause(10 * tosc); // delay 20 µs
Data = spi_ads1243_recv_byte();
Data = (Data << 8) | spi_ads1243_recv_byte();
Data = (Data << 8) | spi_ads1243_recv_byte();
// de-assert CS
ADS1243AssertCS(0);
return Data;
}
float read_pt100_sensor()
{
//#### init clock ADS1243 to 2MHZ
int chan = 0;
unsigned ACRVal;
u8 i;
u32 Data = 0;
s16 sensor_range;
s16 sensor_measurement;
float resistance = 0;
float frac, temperature;
//1-a) reset command
ADS1243SendResetCommand();
//1-b) write setup register
//ADS1243SetGain(ADS1243_GAIN_1);
//1-c) set cjannel
ADS1243AssertCS(1);
spi_ads1243_send_byte(0x51); //write register
Pause(10 * tosc); // delay 20 µs
spi_ads1243_send_byte(0);
Pause(10 * tosc); // delay 20 µs
spi_ads1243_send_byte(0x66);
Pause(10 * tosc); // delay 20 µs
//spi_ads1243_send_byte(2);
ADS1243AssertCS(0);
ADS1243AssertCS(1);
spi_ads1243_send_byte(0x52);
Pause(10 * tosc); // delay 20 µs
spi_ads1243_send_byte(0);
Pause(10 * tosc); // delay 20 µs
spi_ads1243_send_byte(0x20);
Pause(10 * tosc); // delay 20 µs
ADS1243AssertCS(0);
ADS1243AssertCS(1);
spi_ads1243_send_byte(0x11); // register
Pause(10 * tosc); // delay 20 µs
spi_ads1243_send_byte(0);
Pause(10 * tosc); // delay 20 µs
//delay_ticks(2);
i = spi_ads1243_recv_byte();
Pause(10 * tosc);
ADS1243AssertCS(0);
// ADS1243SetChannel(chan | ADS1243_MUXP_AIN0 | ADS1243_MUXP_AIN1 | ADS1243_MUXP_AIN2 | ADS1243_MUXP_AIN3 | ADS1243_MUXP_AIN4 | ADS1243_MUXP_AIN5 | ADS1243_MUXN_AIN6);
// // 1-d) write ACR register data rate = 15Hz (4.91MHz, SPEED = 1)
// ACRVal = SPEED_BIT;
// ADS1243WriteRegister(ADS1243_ACR_REGISTER, 1, &ACRVal);
//selfcal command
ADS1243AssertCS(1);
spi_ads1243_send_byte(ADS1243_CMD_SELFCAL);
ADS1243AssertCS(0);
ADS1243AssertCS(1);
spi_ads1243_send_byte(ADS1243_CMD_DSYNC);
ADS1243AssertCS(0);
// delay_ticks(2);
//while (!(P4IN & ADS1243_DRDY));
Data = ADS1243ReadData(1);
}