完善资料让更多小伙伴认识你,还能领取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 个讨论
|
|
只有小组成员才能发言,加入小组>>
NA555DR VCC最低电压需要在5V供电,为什么用3.3V供电搭了个单稳态触发器也使用正常?
683 浏览 3 评论
MSP430F249TPMR出现高温存储后失效了的情况,怎么解决?
599 浏览 1 评论
对于多级放大电路板,在PCB布局中,电源摆放的位置应该注意什么?
1054 浏览 1 评论
740 浏览 0 评论
普中科技F28335开发板每次上电复位后数码管都会显示,如何熄灭它?
524 浏览 1 评论
请问下tpa3220实际测试引脚功能和官方资料不符,哪位大佬可以帮忙解答下
163浏览 20评论
请教下关于TAS5825PEVM评估模块原理图中不太明白的地方,寻求答疑
127浏览 14评论
在使用3254进行录音的时候出现一个奇怪的现象,右声道有吱吱声,请教一下,是否是什么寄存器设置存在问题?
127浏览 13评论
TLV320芯片内部自带数字滤波功能,请问linein进来的模拟信号是否是先经过ADC的超采样?
123浏览 12评论
TPA6304-Q1: TPA6304 两片公用一组I2C的话,其中一片配置不成功怎么办
170浏览 10评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 02:54 , Processed in 0.883315 second(s), Total 63, Slave 51 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号