完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
再次求助,ads1118要读取第二通道,按如下设置,读到的都是第一通道的值,无法读取第二通道的值,请高人再次指点。感谢!!
#include "msp430x54xA.h" void GPIO_Init(void); void SPI_Init(void); void ADS_Config(void); int ADS_Read(void); signed int WriteSPI(unsigned int Config, unsigned char mode); float Voltage23; void main(void) [ volatile int ADC_Result; WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer GPIO_Init(); SPI_Init(); ADS_Config(); while(1) [ ADS_Config(); ADC_Result = ADS_Read(); // Read data from ADS1118 Voltage23 = ADC_Result*1.0/32768*2.048; __delay_cycles(100); _no_operation(); ] ] void GPIO_Init(void) [ P1OUT |= 0x02; // Set P1.1 for CS P1DIR |= 0x02; // Set P1.1 to output direction P3SEL |= 0x80; // P3.7 option select P5SEL |= 0x30; // P5.4,5 option select P5DIR |= BIT0; // P5.0 Output P5OUT |= BIT0; // P5.0 Output High ] void SPI_Init(void) [ UCB1CTL1 |= UCSWRST; // **Put state machine in reset** UCB1CTL0 |= UCMST+UCSYNC+UCCKPH+UCMSB; // 3-pin, 8-bit SPI master // Clock polarity high, MSB UCB1CTL1 |= UCSSEL_2; // SMCLK UCB1BR0 = 200; // /2 UCB1BR1 = 1; // UCB1CTL1 &= ~UCSWRST; // **Initialize USCI state machine** __delay_cycles(100); // Wait for slave to initialize ] void ADS_Config(void) [ signed int Config_Value; // Initial Config Register Config_Value = 0xB48C; // ADS1118 configuration AIN0/AIN1, FS=+/-2.048, DR=128sps, PULLUP on DOUT P1OUT &=~ 0x02; // Set CS low WriteSPI(Config_Value,0); // Write configuration to ADS1118 P1OUT |= 0x02; // Set CS high ] int ADS_Read(void) [ unsigned int Data, Config_Value; Config_Value = 0xB48C; // ADS1118 configuration AIN0/AIN1, FS=+/-2.048, DR=128sps, PULLUP on DOUT P1OUT &=~ 0x02; // Set CS low Data = WriteSPI(Config_Value,1); // Read data from ADS1118 P1OUT |= 0x02; // Set CS high return Data; ] /* * Mode 0: Only write config register to ADS1118 * Mode 1: Write config register to ADS1118 as well as read data from ADS1118 */ signed int WriteSPI(unsigned int config, unsigned char mode) [ signed int m***; unsigned int temp; volatile signed int dummy; temp = config; if (mode==1) temp = 0; while(!(UCB1IFG&UCTXIFG)); UCB1TXBUF = (temp >> 8 ); // Write MSB of Config while(!(UCB1IFG&UCRXIFG)); m*** = UCB1RXBUF; // Read MSB of Data while(!(UCB1IFG&UCTXIFG)); UCB1TXBUF = (temp & 0xff); // Write LSB of Config while(!(UCB1IFG&UCRXIFG)); m*** = (m*** << 8) | UCB1RXBUF; // Read LSB of Data while(!(UCB1IFG&UCTXIFG)); UCB1TXBUF = (temp >> 8 ); // Write MSB of Config while(!(UCB1IFG&UCRXIFG)); dummy = UCB1RXBUF; // Read MSB of Config while(!(UCB1IFG&UCTXIFG)); UCB1TXBUF= (temp & 0xff); // Write LSB of Config while(!(UCB1IFG&UCRXIFG)); dummy = (dummy <<8) | UCB1RXBUF; // Read LSB of Config __delay_cycles(100); return m***; ] |
|
相关推荐
2 个讨论
|
|
只有小组成员才能发言,加入小组>>
351 浏览 1 评论
546 浏览 2 评论
NA555DR VCC最低电压需要在5V供电,为什么用3.3V供电搭了个单稳态触发器也使用正常?
790 浏览 3 评论
MSP430F249TPMR出现高温存储后失效了的情况,怎么解决?
660 浏览 1 评论
对于多级放大电路板,在PCB布局中,电源摆放的位置应该注意什么?
1140 浏览 1 评论
AT32F407在USART2 DMA发送数据时,接包接到了要发送的数据,程序还是处于等待传输完成的标识判断中,为什么?
84浏览 29评论
306浏览 23评论
请问下tpa3220实际测试引脚功能和官方资料不符,哪位大佬可以帮忙解答下
262浏览 20评论
请教下关于TAS5825PEVM评估模块原理图中不太明白的地方,寻求答疑
210浏览 14评论
两个TMP117传感器一个可以正常读取温度值,一个读取的值一直是0,为什么?
68浏览 13评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-28 13:36 , Processed in 0.457316 second(s), Total 43, Slave 35 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号