完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,
我在STM8S-Discovery上遇到ADC1转换问题。 我已经配置了以下模拟输入: PB4 - AN4 PB5 - AN5 PB6 - AN6 unsigned char ADC_Config_INT(void) { GPIO_Init(ADC_PORT,ADC_15V_PIN,GPIO_MODE_IN_FL_NO_IT); GPIO_Init(ADC_PORT,ADC_CURR_PIN,GPIO_MODE_IN_FL_NO_IT); GPIO_Init(ADC_PORT,ADC_5V_PIN,GPIO_MODE_IN_FL_NO_IT); / * De-Init ADC1外设* / ADC1_DeInit(); / *启用EOC中断* / ADC1_ITConfig(ADC1_IT_EOCIE,ENABLE); / *启用转换数据缓冲* / ADC1_DataBufferCmd(ENABLE); / *启用扫描模式转换* / ADC1_ScanModeCmd(ENABLE); / * Init ADC1外设* / / * ADC1频道4 * / ADC1_Init(ADC1_CONVERSIONMODE_CONtiNUOUS,ADC1_CHANNEL_4,ADC1_PRESSEL_FCPU_D8, ADC1_EXTTRIG_TIM,DISABLE,ADC1_ALIGN_RIGHT,ADC1_SCHMITTTRIG_CHANNEL4, DISABLE); / * ADC1频道5 * / ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS,ADC1_CHANNEL_5,ADC1_PRESSEL_FCPU_D8, ADC1_EXTTRIG_TIM,DISABLE,ADC1_ALIGN_RIGHT,ADC1_SCHMITTTRIG_CHANNEL5, DISABLE); / * ADC1频道6 * / ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS,ADC1_CHANNEL_6,ADC1_PRESSEL_FCPU_D8, ADC1_EXTTRIG_TIM,DISABLE,ADC1_ALIGN_RIGHT,ADC1_SCHMITTTRIG_CHANNEL6, DISABLE); / *启用ADC1 * / ADC1_Cmd(ENABLE); 返回0; } 中断函数代码是: #define ADC_SAMPLES 8 extern volatile uint16_t ValueCh4 [ADC_SAMPLES]; extern volatile uint16_t ValueCh5 [ADC_SAMPLES]; extern volatile uint16_t ValueCh6 [ADC_SAMPLES]; volatile uint8_t Index = 0; extern uint8_t ArrayEmpty; / ** * @brief ADC1中断程序。 * @param无 * @retval没有 * / INTERRUPT_HANDLER(ADC1_IRQHandler,22) { if(ADC1_GetFlagStatus(ADC1_FLAG_EOC)!= RESET) { ValueCh4 [Index] = ADC1_GetBufferValue(4); ValueCh5 [Index] = ADC1_GetBufferValue(5); ValueCh6 [Index] = ADC1_GetBufferValue(6); // Controlla se ho acquisito un numero sufficiente di campioni if(Index> = ADC_SAMPLES) { ArrayEmpty = 1; 指数= 0; } 其他{ 指数++; } ADC1_ClearFlag(ADC1_FLAG_EOC); } 返回; } ''ADC1_GetBufferValue''函数仅在第一次返回正确的值。 例如,如果我修改PB4引脚上的值,则读取前一个值时继续。 任何想法? 谢谢 以上来自于谷歌翻译 以下为原文 Hi, I have problem with ADC1 conversions on STM8S-Discovery. I have configured the analogic inputs following: PB4 - AN4 PB5 - AN5 PB6 - AN6 unsigned char ADC_Config_INT ( void ) { GPIO_Init(ADC_PORT,ADC_15V_PIN, GPIO_MODE_IN_FL_NO_IT); GPIO_Init(ADC_PORT,ADC_CURR_PIN, GPIO_MODE_IN_FL_NO_IT); GPIO_Init(ADC_PORT,ADC_5V_PIN, GPIO_MODE_IN_FL_NO_IT); /* De-Init ADC1 peripheral */ ADC1_DeInit(); /* Enable EOC interrupt */ ADC1_ITConfig(ADC1_IT_EOCIE, ENABLE); /* Enable conversion data buffering */ ADC1_DataBufferCmd(ENABLE); /* Enable scan mode conversion */ ADC1_ScanModeCmd(ENABLE); /* Init ADC1 peripheral */ /* ADC1 Channel 4 */ ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_4, ADC1_PRESSEL_FCPU_D8, ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL4, DISABLE); /* ADC1 Channel 5 */ ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_5, ADC1_PRESSEL_FCPU_D8, ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL5, DISABLE); /* ADC1 Channel 6 */ ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_6, ADC1_PRESSEL_FCPU_D8, ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL6, DISABLE); /* Enable ADC1 */ ADC1_Cmd(ENABLE); return 0; } the interrupt function code is: #define ADC_SAMPLES 8 extern volatile uint16_t ValueCh4[ADC_SAMPLES]; extern volatile uint16_t ValueCh5[ADC_SAMPLES]; extern volatile uint16_t ValueCh6[ADC_SAMPLES]; volatile uint8_t Index = 0; extern uint8_t ArrayEmpty; /** * @brief ADC1 interrupt routine. * @param None * @retval None */ INTERRUPT_HANDLER(ADC1_IRQHandler, 22) { if ( ADC1_GetFlagStatus(ADC1_FLAG_EOC) != RESET ) { ValueCh4[Index] = ADC1_GetBufferValue(4); ValueCh5[Index] = ADC1_GetBufferValue(5); ValueCh6[Index] = ADC1_GetBufferValue(6); // Controlla se ho acquisito un numero sufficiente di campioni if( Index >= ADC_SAMPLES ) { ArrayEmpty = 1; Index = 0; } else{ Index++; } ADC1_ClearFlag(ADC1_FLAG_EOC); } return; } The ''ADC1_GetBufferValue'' function return the value correct the first time only. If I modified the value on pin PB4 for example, continuos at read the previous value. Any idea? Thanks |
|
相关推荐
5个回答
|
|
我附上了这个项目。
发生ADC中断,但“ADC1_GetBufferValue(ADC1_CHANNEL_4)”没有 返回通道4上的更新值。此函数返回读取的第一个值。 有什么建议么? 谢谢 以上来自于谷歌翻译 以下为原文 I attached the project. The ADC interrupt is occurs, but the ''ADC1_GetBufferValue(ADC1_CHANNEL_4)'' not return the updated value on the channel 4. This function return the read first value. Any suggestions? Thanks |
|
|
|
|
|
|
|
我有一个类似的问题...我必须重新启动程序来刷新这个值。
以上来自于谷歌翻译 以下为原文 I am having a similar issue... I have to restart the program to refresh this value. |
|
|
|
您应该再次阅读参考手册中的ADC章节。您的连续扫描模式始终自动转换N个通道(来自通道0)。多渠道c
不推荐连续扫描。 您可以在每个通道上将定时器触发器与单一模式结合使用,请参阅@LaserElettronicaSRL的帖子 以上来自于谷歌翻译 以下为原文 You should read ADC chapter in reference manual again. Your continuous scan mode is always convert N channels (from channel 0) automatically. Multi channel c ontinuous scan is not recommend. You can combine timer trigger with single mode on each channel, refer post of @LaserElettronicaSRL |
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2644 浏览 1 评论
3209 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1784 浏览 1 评论
3613 浏览 6 评论
5990 浏览 21 评论
940浏览 4评论
1317浏览 4评论
在Linux上安装Atollic TRUEStudio的步骤有哪些呢?
585浏览 3评论
使用DMA激活某些外设会以导致外设无法工作的方式生成代码是怎么回事
1304浏览 3评论
1362浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 23:56 , Processed in 1.142244 second(s), Total 57, Slave 50 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号