打印
[STM8]

STM8L152 串口问题

[复制链接]
5811|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
zz19890629|  楼主 | 2011-12-22 10:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
利用STM8L中断接收多个字节  无法实现,例如我发16进制的12 34  只能接收12。34就接收不到了  不知道原因 以下是我的程序
void usart_init(void)
{
USART_DeInit(USART1);
USART_Init(USART1, (uint32_t)115200, USART_WordLength_8b
               , USART_StopBits_1,USART_Parity_No,(USART_Mode_TypeDef)USART_Mode_Tx | USART_Mode_Rx);
USART_ClockInit( USART1,USART_Clock_Disable,USART_CPOL_Low,USART_CPHA_2Edge,USART_LastBit_Disable);
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
USART_ClearITPendingBit(USART1,USART_IT_RXNE);
USART_Cmd(USART1, ENABLE);
}
void clk_config(void)
{
CLK_PeripheralClockConfig(CLK_Peripheral_USART1, ENABLE);
}
void gpio_config(void)
{
GPIO_Init(TX_PORT,TX_PIN,GPIO_Mode_Out_PP_Low_Fast);
GPIO_Init(RX_PORT,RX_PIN,GPIO_Mode_In_FL_No_IT);
GPIO_Init(LED_PORT,LED_PIN,GPIO_Mode_Out_PP_Low_Fast);
}


main()
{
  clk_config();
usart_init();
  SYSCFG_REMAPPinConfig(REMAP_Pin_USART1TxRxPortC,ENABLE);
gpio_config();
enableInterrupts();

while(1)
{;}
}


中断程序
#include  "stm8l15x.h"
#include  "stm8l15x_usart.h"
unsigned char b=0;
unsigned char Tab_rx_1[21]={0x00};
typedef void @far (*interrupt_handler_t)(void);
struct interrupt_vector {
unsigned char interrupt_instruction;
interrupt_handler_t interrupt_handler;
};
@far @interrupt void NonHandledInterrupt (void)
{
/* in order to detect unexpected events during development,
    it is recommended to set a breakpoint on the following instruction
*/
return;
}
@far @interrupt void USART1_RX (void)
{
if(USART_GetITStatus(USART1,USART_IT_RXNE)==SET)

  b=USART_ReceiveData8(USART1);

  USART_ClearITPendingBit(USART1,USART_IT_RXNE);
   

return;
}
extern void _stext();     /* startup routine */
struct interrupt_vector const _vectab[] = {
{0x82, (interrupt_handler_t)_stext}, /* reset */
{0x82, NonHandledInterrupt}, /* trap  */
{0x82, NonHandledInterrupt}, /* irq0  */
{0x82, NonHandledInterrupt}, /* irq1  */
{0x82, NonHandledInterrupt}, /* irq2  */
{0x82, NonHandledInterrupt}, /* irq3  */
{0x82, NonHandledInterrupt}, /* irq4  */
{0x82, NonHandledInterrupt}, /* irq5  */
{0x82, NonHandledInterrupt}, /* irq6  */
{0x82, NonHandledInterrupt}, /* irq7  */
{0x82, NonHandledInterrupt}, /* irq8  */
{0x82, NonHandledInterrupt}, /* irq9  */
{0x82, NonHandledInterrupt}, /* irq10 */
{0x82, NonHandledInterrupt}, /* irq11 */
{0x82, NonHandledInterrupt}, /* irq12 */
{0x82, NonHandledInterrupt}, /* irq13 */
{0x82, NonHandledInterrupt}, /* irq14 */
{0x82, NonHandledInterrupt}, /* irq15 */
{0x82, NonHandledInterrupt}, /* irq16 */
{0x82, NonHandledInterrupt}, /* irq17 */
{0x82, NonHandledInterrupt}, /* irq18 */
{0x82, NonHandledInterrupt}, /* irq19 */
{0x82, NonHandledInterrupt}, /* irq20 */
{0x82, NonHandledInterrupt}, /* irq21 */
{0x82, NonHandledInterrupt}, /* irq22 */
{0x82, NonHandledInterrupt}, /* irq23 */
{0x82, NonHandledInterrupt}, /* irq24 */
{0x82, NonHandledInterrupt}, /* irq25 */
{0x82, NonHandledInterrupt}, /* irq26 */
{0x82, NonHandledInterrupt}, /* irq27 */
{0x82, USART1_RX}, /* irq28 */
{0x82, NonHandledInterrupt}, /* irq29 */
};


请大哥们帮帮忙~
沙发
nikita-fuck| | 2011-12-22 10:51 | 只看该作者
好问题。值得收藏!
就等答案

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

8

帖子

1

粉丝