完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,
我已经采用了stm8l-discovery评估板附带的一些示例代码来尝试与stm8上的hyperterm通信。当我尝试发送任何东西时,我看到的是在Hypeerm屏幕上的垃圾...我已经验证了双方都有相同的设置,115200,没有极性,1个停止位,8位字长 - 但是它仍然不起作用。 我可以帮忙解决这个问题吗?我的示例代码片段如下 - 有人可以解释我做错了什么吗? & sharpdefine DBG_COM1 USART1 & sharpdefine DBG_COM1_GPIO GPIOC & sharpdefine DBG_COM1_CLK CLK_Peripheral_USART1 & sharpdefine DBG_COM1_RxPin GPIO_Pin_2 & sharpdefine DBG_COM1_TxPin GPIO_Pin_3 & sharpdefine DBG_COM1_ClkPin GPIO_Pin_4 typedef enum { COM1 = 0 } COM_TypeDef; USART_TypeDef * COM_USART [COMn] = { DBG_COM1 }; GPIO_TypeDef * COM_PORT [COMn] = { DBG_COM1_GPIO }; const uint8_t COM_USART_CLK [COMn] = { DBG_COM1_CLK }; const uint8_t COM_TX_PIN [COMn] = { DBG_COM1_TxPin }; const uint8_t COM_RX_PIN [COMn] = { DBG_COM1_RxPin }; const uint8_t COM_CLK_PIN [COMn] = { DBG_COM1_ClkPin }; static void COMInit(COM_TypeDef COM,uint32_t USART_BaudRate, USART_WordLength_TypeDef USART_WordLength, USART_StopBits_TypeDef USART_StopBits, USART_Parity_TypeDef USART_Parity, USART_Mode_TypeDef USART_Mode) { (COM_USART [COM])USART_DeInit; / *启用USART时钟* / CLK_PeripheralClockConfig((CLK_Peripheral_TypeDef)COM_USART_CLK [COM],ENABLE); / *将USART Tx配置为备用功能推挽(软件上拉)* / GPIO_ExternalPullUpConfig(COM_PORT [COM],COM_TX_PIN [COM] | COM_RX_PIN [COM],ENABLE); / * USART配置* / USART_Init(COM_USART [COM],USART_BaudRate, USART_WordLength, USART_StopBits, USART_Parity, USART_MODE); } 主要() { ... COMInit(COM1,(uint32_t)115200,USART_WordLength_8b,USART_StopBits_1, USART_Parity_No,USART_Mode_Tx | USART_Mode_Rx); USART_Cmd(COM_USART [COM1],ENABLE); //尝试向hyperterm发送几个字节 USART_SendData8(DBG_COM1,0x41); while(USART_GetFlagStatus(DBG_COM1,USART_FLAG_TC)== RESET); USART_SendData8(DBG_COM1,0x42); while(USART_GetFlagStatus(DBG_COM1,USART_FLAG_TC)== RESET); ... 当我做这些写操作时,我看到的就是PC超级电脑屏幕上的垃圾...... 我的h / w设置如下: PC2引脚在DB9连接器上跳线到TX PC3引脚跳线到DB9连接器上的RX #USART,RS232 以上来自于谷歌翻译 以下为原文 Hi All, I have taken some of the sample code that comes with the stm8l-discovery eval board to try and talk to hyperterm on from stm8. when i try to send anything all I see is garbage on the hyperterm screen... I have verified both side have the same settings, 115200, no polarity, 1 stop bit, 8 bit word length - butstill it does not work. Can I get some help to get this working? My sample code snippet is as follows - can someone explain what I am doing wrong? &sharpdefine DBG_COM1 USART1 &sharpdefine DBG_COM1_GPIO GPIOC &sharpdefine DBG_COM1_CLK CLK_Peripheral_USART1 &sharpdefine DBG_COM1_RxPin GPIO_Pin_2 &sharpdefine DBG_COM1_TxPin GPIO_Pin_3 &sharpdefine DBG_COM1_ClkPin GPIO_Pin_4 typedef enum { COM1 = 0 } COM_TypeDef; USART_TypeDef* COM_USART[COMn] = { DBG_COM1 }; GPIO_TypeDef* COM_PORT[COMn] = { DBG_COM1_GPIO }; const uint8_t COM_USART_CLK[COMn] = { DBG_COM1_CLK }; const uint8_t COM_TX_PIN[COMn] = { DBG_COM1_TxPin }; const uint8_t COM_RX_PIN[COMn] = { DBG_COM1_RxPin }; const uint8_t COM_CLK_PIN[COMn] = { DBG_COM1_ClkPin }; static void COMInit(COM_TypeDef COM, uint32_t USART_BaudRate, USART_WordLength_TypeDef USART_WordLength, USART_StopBits_TypeDef USART_StopBits, USART_Parity_TypeDef USART_Parity, USART_Mode_TypeDef USART_Mode) { USART_DeInit(COM_USART[COM]); /* Enable USART clock */ CLK_PeripheralClockConfig((CLK_Peripheral_TypeDef)COM_USART_CLK[COM], ENABLE); /* Configure USART Tx as alternate function push-pull (software pull up)*/ GPIO_ExternalPullUpConfig(COM_PORT[COM], COM_TX_PIN[COM] | COM_RX_PIN[COM] , ENABLE); /* USART configuration */ USART_Init(COM_USART[COM], USART_BaudRate, USART_WordLength, USART_StopBits, USART_Parity, USART_Mode); } main() { ... COMInit(COM1, (uint32_t)115200, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No, USART_Mode_Tx | USART_Mode_Rx); USART_Cmd(COM_USART[COM1], ENABLE); //try to send a few bytes to hyperterm USART_SendData8(DBG_COM1, 0x41); while (USART_GetFlagStatus(DBG_COM1, USART_FLAG_TC) == RESET); USART_SendData8(DBG_COM1, 0x42); while (USART_GetFlagStatus(DBG_COM1, USART_FLAG_TC) == RESET); ... when i do these writes all I see is garbage on PC hyperterm screen... My h/w setup is as follows: PC2 pin jumpered to TX on DB9 connector PC3 pin jumpered to RX on DB9 connector #usart-rs232 |
|
相关推荐
2个回答
|
|
嗨,
如果你看到垃圾,我认为你可能有波特率问题。首先,我将检查波特率初始化。 实际上,如果您检查驱动程序功能,则波特率频率取决于CPU时钟频率。我建议你检查一下这些要点: >检查您的应用中使用的时钟(LSI,HSI,...); >检查CPU时钟频率; >检查USART寄存器设置的值; 这是第一种方式.... 其他要点,问题: >在您的应用程序中,您是否逐个发送caracters(在第一个字符发送后放置一个断点(line:while(....))并检查它。 >您是否尝试过超级终端的接待? 我希望这些观点可以帮到你。 最好的祝福 菲利普 大家好, 我已经采用了stm8l-discovery评估板附带的一些示例代码来尝试与stm8上的hyperterm通信。当我尝试发送任何东西时,我看到的是在Hypeerm屏幕上的垃圾...我已经验证了双方都有相同的设置,115200,没有极性,1个停止位,8位字长 - 但是它仍然不起作用。 我可以帮忙解决这个问题吗?我的示例代码片段如下 - 有人可以解释我做错了什么吗? #define DBG_COM1 USART1 #define DBG_COM1_GPIO GPIOC #define DBG_COM1_CLK CLK_Peripheral_USART1 #define DBG_COM1_RxPin GPIO_Pin_2 #define DBG_COM1_TxPin GPIO_Pin_3 #define DBG_COM1_ClkPin GPIO_Pin_4 typedef enum { COM1 = 0 } COM_TypeDef; USART_TypeDef * COM_USART [COMn] = { DBG_COM1 }; GPIO_TypeDef * COM_PORT [COMn] = { DBG_COM1_GPIO }; const uint8_t COM_USART_CLK [COMn] = { DBG_COM1_CLK }; const uint8_t COM_TX_PIN [COMn] = { DBG_COM1_TxPin }; const uint8_t COM_RX_PIN [COMn] = { DBG_COM1_RxPin }; const uint8_t COM_CLK_PIN [COMn] = { DBG_COM1_ClkPin }; static void COMInit(COM_TypeDef COM,uint32_t USART_BaudRate, USART_WordLength_TypeDef USART_WordLength, USART_StopBits_TypeDef USART_StopBits, USART_Parity_TypeDef USART_Parity, USART_Mode_TypeDef USART_Mode) { (COM_USART [COM])USART_DeInit; / *启用USART时钟* / CLK_PeripheralClockConfig((CLK_Peripheral_TypeDef)COM_USART_CLK [COM],ENABLE); / *将USART Tx配置为备用功能推挽(软件上拉)* / GPIO_ExternalPullUpConfig(COM_PORT [COM],COM_TX_PIN [COM] | COM_RX_PIN [COM],ENABLE); / * USART配置* / USART_Init(COM_USART [COM],USART_BaudRate, USART_WordLength, USART_StopBits, USART_Parity, USART_MODE); } 主要() { ... COMInit(COM1,(uint32_t)115200,USART_WordLength_8b,USART_StopBits_1, USART_Parity_No,USART_Mode_Tx | USART_Mode_Rx); USART_Cmd(COM_USART [COM1],ENABLE); //尝试向hyperterm发送几个字节 USART_SendData8(DBG_COM1,0x41); while(USART_GetFlagStatus(DBG_COM1,USART_FLAG_TC)== RESET); USART_SendData8(DBG_COM1,0x42); while(USART_GetFlagStatus(DBG_COM1,USART_FLAG_TC)== RESET); ... 当我做这些写操作时,我看到的就是PC超级电脑屏幕上的垃圾...... 我的h / w设置如下: PC2引脚在DB9连接器上跳线到TX PC3引脚跳线到DB9连接器上的RX 以上来自于谷歌翻译 以下为原文 Hi, If you see garbage, I think that you have perhaps baud rate problems. In first I will check the baud rate initialization. In fact, if you check in the driver functions the baud rate frequency depends of CPU clock frequency. I can suggest to you to check if these points: > Check which clock is used in your application (LSI, HSI, ...); > Check the CPU clock frequency; > Check in USART register the values setted; This is the first way .... Other points, questions: > In you application do you send the caracters one by one (place one break point after the first caracter is sent ( line: while( ....) ) and check it.? > Have you try the reception from hyperterminal? I hope that these points can help you. Best regards Philippe Hi All, I have taken some of the sample code that comes with the stm8l-discovery eval board to try and talk to hyperterm on from stm8. when i try to send anything all I see is garbage on the hyperterm screen... I have verified both side have the same settings, 115200, no polarity, 1 stop bit, 8 bit word length - butstill it does not work. Can I get some help to get this working? My sample code snippet is as follows - can someone explain what I am doing wrong? #define DBG_COM1 USART1 #define DBG_COM1_GPIO GPIOC #define DBG_COM1_CLK CLK_Peripheral_USART1 #define DBG_COM1_RxPin GPIO_Pin_2 #define DBG_COM1_TxPin GPIO_Pin_3 #define DBG_COM1_ClkPin GPIO_Pin_4 typedef enum { COM1 = 0 } COM_TypeDef; USART_TypeDef* COM_USART[COMn] = { DBG_COM1 }; GPIO_TypeDef* COM_PORT[COMn] = { DBG_COM1_GPIO }; const uint8_t COM_USART_CLK[COMn] = { DBG_COM1_CLK }; const uint8_t COM_TX_PIN[COMn] = { DBG_COM1_TxPin }; const uint8_t COM_RX_PIN[COMn] = { DBG_COM1_RxPin }; const uint8_t COM_CLK_PIN[COMn] = { DBG_COM1_ClkPin }; static void COMInit(COM_TypeDef COM, uint32_t USART_BaudRate, USART_WordLength_TypeDef USART_WordLength, USART_StopBits_TypeDef USART_StopBits, USART_Parity_TypeDef USART_Parity, USART_Mode_TypeDef USART_Mode) { USART_DeInit(COM_USART[COM]); /* Enable USART clock */ CLK_PeripheralClockConfig((CLK_Peripheral_TypeDef)COM_USART_CLK[COM], ENABLE); /* Configure USART Tx as alternate function push-pull (software pull up)*/ GPIO_ExternalPullUpConfig(COM_PORT[COM], COM_TX_PIN[COM] | COM_RX_PIN[COM] , ENABLE); /* USART configuration */ USART_Init(COM_USART[COM], USART_BaudRate, USART_WordLength, USART_StopBits, USART_Parity, USART_Mode); } main() { ... COMInit(COM1, (uint32_t)115200, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No, USART_Mode_Tx | USART_Mode_Rx); USART_Cmd(COM_USART[COM1], ENABLE); //try to send a few bytes to hyperterm USART_SendData8(DBG_COM1, 0x41); while (USART_GetFlagStatus(DBG_COM1, USART_FLAG_TC) == RESET); USART_SendData8(DBG_COM1, 0x42); while (USART_GetFlagStatus(DBG_COM1, USART_FLAG_TC) == RESET); ... when i do these writes all I see is garbage on PC hyperterm screen... My h/w setup is as follows: PC2 pin jumpered to TX on DB9 connector PC3 pin jumpered to RX on DB9 connector |
|
|
|
嗨,
我不确定,但你可能需要stm8l-discovery和PC端口之间的电平转换器? 以上来自于谷歌翻译 以下为原文 Hi, i'm not sure, but you may need a level shifter between stm8l-discovery and PC port? |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2730 浏览 1 评论
3239 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1808 浏览 1 评论
3647 浏览 6 评论
6035 浏览 21 评论
1338浏览 4评论
198浏览 3评论
对H747I-DISCO写程序时将CN2的st-link复用为usart1,再次烧录时无法检测到stlink怎么解决?
350浏览 2评论
STM32G474RE芯片只是串口发个数据就发烫严重是怎么回事?
442浏览 2评论
STM32处理增量式编码器Z信号如何判断中断是正转的还是反向转的?
273浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 04:29 , Processed in 2.134887 second(s), Total 78, Slave 61 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号