This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi all. I have a project that read/write temperature and pressure from MS5541C. I follow these instructions in datasheet but still can't get right values. I'm always get the same value for both temp and press. I don't know where it came wrong.
The sensor use SPI to communicate with MSP430, it generate 64-bit calibration data (partition into 4 words of 16-bit) for highly accurate press and temp calculation. First, you have to read all Words by sending 16-bit frame that specific for each word. After sensor received frame, it will generate 16-bit Word in buffer, you continue send dummy data to received this Word back (SPI protocol). After reading all Words, continue to read pressure and temp value follow same steps but a little different. The different here is that after received frame, the sensor need time to convert analog data to digital, it took about 35ms to do this, so you need to wait before reading back. You can read more detail from datasheet i attached with this post.
Here my code:
// SPI configure
P1SEL |= (BIT6 + BIT7 + BIT5); // p1.6=MISO, p1.7=MOSI, p1.5=UCB0CLK
P1SEL2 |= (BIT6 + BIT7 + BIT5);
UCB0CTL1 |= UCSWRST;
UCB0CTL0 |= (UCMSB + UCMST + UCSYNC); // 3-pin, 8-bit SPI master
UCB0CTL0 &= ~UCCKPL;
UCB0CTL1 |= UCSSEL_2; // SMCLK
UCB0BR0 |= 0x02; // /2
UCB0BR1 = 0; //
UCB0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
i'm using an external crystal for 32kHz clock signal supply for sensor to ADC.
// configure ACLK. Source form 32kHz Micro Crystal
BCSCTL1 |= DIVA_0; // ACLK/1
BCSCTL3 |= XCAP_3;
P1DIR |= BIT0;
P1SEL |= BIT0; // p1.0=ACLK
This is my read word code.
// reset. Sending frame must occur on the rising edge of SCLK, and receive on falling edge.
// P1OUT &= ~BIT6;
UCB0CTL1 |= UCSWRST;
UCB0CTL0 &= ~UCCKPH; // config to send on rising edge SCLK
UCB0CTL0 &= ~UCCKPL;
UCB0CTL1 &= ~UCSWRST;
while (UCB0STAT & UCBUSY);
UCB0TXBUF = 0x15;
while (UCB0STAT & UCBUSY);
UCB0TXBUF = 0x55;
while (UCB0STAT & UCBUSY);
UCB0TXBUF = 0x40;
// P1OUT|= BIT6;
// read word1
// P1OUT &= ~BIT6;
while (UCB0STAT & UCBUSY);
UCB0TXBUF = 0x1D;
while (UCB0STAT & UCBUSY);
UCB0TXBUF = 0x50;
while (UCB0STAT & UCBUSY);
UCB0CTL1 |= UCSWRST; // config to received on falling edge of SCLK.
UCB0CTL0 |= UCCKPH;
UCB0CTL0 &= ~UCCKPL;
UCB0CTL1 &= ~UCSWRST;
UCB0TXBUF = 0x00; // Send dummy byte to read 8MSB
while (UCB0STAT & UCBUSY); // wait until Rx buff received
Word1 = UCB0RXBUF;
UCB0TXBUF = 0x00; // Send dummy byte to read 8LSB
Word1 <<= 8; // shift 8 bit to left
while (UCB0STAT & UCBUSY); // transmission completed
Word1 |= UCB0RXBUF;
// same for word 2, 3, 4.
this is my read press/temp code:
// read D1
// reset first
while (UCB0STAT & UCBUSY);
UCB0TXBUF = 0x0F;
while (UCB0STAT & UCBUSY);
UCB0TXBUF = 0x40;
// while (!(IFG2 & UCB0RXIFG)); // stuck here if use while loop in comment. I don't know why, it's always send back.
UCB0CTL1 |= UCSWRST;
UCB0CTL0 |= UCCKPH;
UCB0CTL0 &= ~UCCKPL;
UCB0CTL1 &= ~UCSWRST;
while(P1IN & BIT6); // when MISO go down, it mean the conversion is completed.
__delay_cycles(2000);
UCB0TXBUF = 0x00; // Send dummy byte to read 8MSB
while (UCB0STAT & UCBUSY); // wait until Rx buff received
D1 = UCB0RXBUF;
UCB0TXBUF = 0x00;
D1 <<= 8; // shift 8 bit to left
while (UCB0STAT & UCBUSY); // transmission completed
D1 |= UCB0RXBUF;
Thanks for your help.
**Attention** This is a public forum