我正在使用stm8l151 ... MCU,并且试图通过Uart1向HTerminal发送不同的字符串。我有三个不同的字符串要发送。前两个字符串已完全传输,但是当发送第三个字符串时,它被截断了,并且它开始反复重复发送第一个和第二个字符串,但是当我逐步执行代码时,它就可以正常工作。但是如果我允许代码运行,就会出现问题。
我附上了Hterm( uart_com )的输出,以便于更好地理解,以及代码的某些部分( uart send和uart_init )
只是为了更好地理解附加的输出,字符串(cmd 1、2和3)分别是 at + nrb , at + cfun = 1 和 at + cops = 1,2,“ 26201”
请,任何建议将不胜感激。
void nbiot_buf_transmit(void){
for(int i=0 ; i < sizeof(cmd1);i++){
USART_SendData8(USART1,((uint8_t)cmd1[i]));
while(!(USART1->SR));
while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);
}
for(int i=0 ; i < sizeof(cmd2);i++){
USART_SendData8(USART1,((uint8_t)cmd2[i]));
while(!(USART1->SR));
while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);
}
for(int i=0 ; i < sizeof(cmd3);i++){
USART_SendData8(USART1,((uint8_t)cmd3[i]));
while(!(USART1->SR));
while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);
}
void uart_init(void){
/* init Tx and Rx Pins */
GPIO_Init(GPIOC, GPIO_Pin_3, GPIO_Mode_Out_PP_High_Fast); //tx pin output
GPIO_Init(GPIOC, GPIO_Pin_2, GPIO_Mode_In_FL_No_IT); //rx pin input
/* enable usart1 clk */
(CLK->PCKENR1 |= (uint8_t)((uint8_t)1 << ((uint8_t)CLK_Peripheral_USART1 &
(uint8_t)0x0F)));
/* config for GPIO mode */
(CLK->PCKENR2 |= (uint8_t)((uint8_t)1 << ((uint8_t)CLK_Peripheral_COMP &
(uint8_t)0x0F)));
(RI->IOCMR3 &= 0xFD);
(RI->IOSR3 &= (uint8_t) (~(uint8_t) ((uint8_t)1 << (uint8_t) (RI_IOSwitch_6
& (uint8_t) 0x0F))));
(CLK->PCKENR2 &= (uint8_t)(~(uint8_t)(((uint8_t)1 <<
((uint8_t)CLK_Peripheral_COMP & (uint8_t)0x0F)))));
/* init usart peripheral */
USART_Init(USART1,
(PAL_dwCLK_FREQ_VALUE/9600),
USART_WordLength_8b,
USART_StopBits_1,
USART_Parity_No,
USART_Mode_Rx); //Rx enable
ITC->ISPR8 &= 0xFC; // Set USART1_RX_IRQn on ITC_PriorityLevel_2
ITC->ISPR7 &= 0x3F; // Set USART1_TX_IRQn on ITC_PriorityLevel_2
/* enable usart1 peripheral */
USART_Cmd(USART1,ENABLE)
}