主题中讨论的其他器件:MSP430F5529、
您好!
在我的体重秤设计中、我使用以下代码在 ADS1231和 MSP430F5529之间进行通信。 结果数据如下所示。 如您所见、每个数据点的最后两个字节按预期一致、但第一个字节 会有所不同。 造成这种不一致的原因是什么? SPI 协议的传输的第一个字节是否有问题? 我们非常感谢您的帮助。
/* * main.c * * Updated on: Oct 22, 2020 * Author: Yamen Alimam */ #include <msp430.h> #include <stdint.h> #include <stdio.h> int main(void) { WDTCTL = WDTPW | WDTHOLD; // hold watchdog timer UCB0CTL1 |= UCSWRST; // software reset enable P3SEL = BIT1 + BIT2; // configure SPI pins (P3.1 = MISO, P3.2 = SCLK) P2DIR |= BIT2 + BIT3; // P2.2 = SPEED, P2.3 = PWDN, outputs P2OUT = 0x08; // 10 SPS, active UCB0CTL0 = UCMST + UCSYNC + UCMODE_0 + UCMSB; // master mode, msb first, synchronous UCB0CTL1 |= UCSSEL_3; // select SMCLK (1 MHz) UCB0CTL1 &= ~UCSWRST; // initialize SPI interface int32_t data1, code; int16_t data2; int8_t data3; while (1) { if((P1IN & 0x08) == 0) { while (!(UCB0IFG & UCTXIFG)); UCB0TXBUF = 0x21; while (!(UCRXIFG)); // if RX operation is not complete, continue data1 = UCB0RXBUF; while (!(UCB0IFG & UCTXIFG)); UCB0TXBUF = 0x22; while (!(UCRXIFG)); data2 = UCB0RXBUF; while (!(UCB0IFG & UCTXIFG)); UCB0TXBUF = 0x23; while (!(UCRXIFG)); data3 = UCB0RXBUF; code = (data1 << 16) + (data2 << 8) + data3 + 0x800000; code &= 0x00ffffff; printf("The code is %lx\n", code); } } }