利用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 */
};
请大哥们帮帮忙~ |
|