Forum: Mikrocontroller und Digitale Elektronik STM32 - USART Receive Interrupt


von Rene K. (xdraconix)


Lesenswert?

Ich habe hier ein Problem, ich möchte über einen STM21F103RB mit einem 
ESP8266 kommunizieren. Diesen habe ich am USART3 - Daten schicken klappt 
soweit auch ganz gut, nur das Empfangen macht mir gerade Probleme. Ich 
komme nicht in den Interrupt Handler.

Hier mal die Init der USART:
1
void uart_ESP8266_Init(void)
2
{
3
  // use PB11 (RX) and PB10 (TX)
4
  // USART3
5
6
  // enable clock for USART3, GPIOB, AFIO
7
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
8
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
9
  GPIO_InitTypeDef gpioInitStruct;
10
11
  // init TX Pin
12
  gpioInitStruct.GPIO_Pin = GPIO_Pin_10;
13
  gpioInitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
14
  gpioInitStruct.GPIO_Speed = GPIO_Speed_50MHz;
15
  GPIO_Init(GPIOB, &gpioInitStruct);
16
  // init RX Pin
17
  gpioInitStruct.GPIO_Pin = GPIO_Pin_11;
18
  gpioInitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
19
  GPIO_Init(GPIOB, &gpioInitStruct);
20
21
  // init RST Pin
22
  gpioInitStruct.GPIO_Pin = GPIO_Pin_8;
23
  gpioInitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
24
  GPIO_Init(GPIOB, &gpioInitStruct);
25
26
  // init Ch_PD Pin
27
  gpioInitStruct.GPIO_Pin = GPIO_Pin_9;
28
  gpioInitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
29
  GPIO_Init(GPIOB, &gpioInitStruct);
30
31
  // SET Reset and Ch_PD Pin
32
  GPIO_SetBits(GPIOB,GPIO_Pin_9);
33
  GPIO_SetBits(GPIOB,GPIO_Pin_8);
34
35
  // setup USART3:
36
  USART_InitTypeDef usartInitStruct;
37
  USART_StructInit(&usartInitStruct);
38
39
  usartInitStruct.USART_BaudRate = 115200;
40
  usartInitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
41
  USART_Init(USART3, &usartInitStruct);
42
  USART_Cmd(USART3, ENABLE);
43
44
  /* Enable the USART3 Interrupt */
45
  NVIC_InitTypeDef NVIC_InitStructure;
46
    NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
47
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
48
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
49
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
50
    NVIC_Init(&NVIC_InitStructure);
51
52
}

Hier der Interrupt - als erstes setze ich eine LED um sehen ob der Int 
überhaupt ausgelöst wird - da tut sich schon nix:
1
void USART3_IRQHandler(void)
2
{
3
  GPIO_SetBits(GPIOA,GPIO_Pin_5); //DEBUG
4
  if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
5
  {
6
    /* Read one byte from the receive data register */
7
    bufferRx[RxCounter++] = USART_ReceiveData(USART3);
8
    GPIO_SetBits(GPIOA,GPIO_Pin_5);
9
    //USART_SendData(USART1, bufferRx[RxCounter-1]);//echo
10
    if(bufferRx[RxCounter-1]=='\r'){
11
       strcpy(receiveRx, bufferRx);
12
       receiveRx[RxCounter-1]='\0';
13
       RxCounter=0;printRx=1;
14
      }
15
    if(RxCounter > 125)
16
    {
17
      /* Disable the USART1 Receive interrupt */
18
      USART_ITConfig(USART3, USART_IT_RXNE, DISABLE);
19
20
    }
21
  }
22
 }


Wenn ich aber direkt nach dem Senden den Buffer mit (folgenden Code) 
abfrage, bekomme ich allerdings ein Zeichen zurück:
1
char uart_getc (USART_TypeDef* USARTx)
2
{
3
  assert_param(IS_USART_123_PERIPH(USARTx));
4
5
  while (USART_GetFlagStatus(USARTx, USART_FLAG_RXNE) == RESET);
6
  return  USARTx->DR & 0xff;
7
}

Hat da jemand einen Tipp für mich parat warum die Interrupt Routine 
nicht angesprungen wird?!

von Arduinoquäler (Gast)


Lesenswert?

Rene K. schrieb:
> USART_ITConfig

gehört in die Konfiguration des IRQs, nicht in den IRQ Handler.

also etwa so:
1
    // RX-Interrupt enable
2
    USART_ITConfig (myUART, USART_IT_RXNE, ENABLE);

von Rene K. (xdraconix)


Lesenswert?

Arduinoquäler schrieb:
> Rene K. schrieb:
>> USART_ITConfig
>
> gehört in die Konfiguration des IRQs, nicht in den IRQ Handler.
>
> also etwa so:
>     // RX-Interrupt enable
>     USART_ITConfig (myUART, USART_IT_RXNE, ENABLE);

Ahhhhh... ja hab ich doch glatt übersehen sowie vergessen :-D

Danke für die Hilfe!

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.