Stm32F103 empfängt keine RTR Nachricht. gelöst

OP #7689066
Lesenswert?

Hallo,

ich habe hier ein Nucleo F302R8 Board als Sender und ein Stm32 Bluepill Board als Empfänger. Senden von Datenpackten geht in beide Richtungen. Jetzt wollte ich die RTR Nachrichten testen und das Bluepill Board empfängt keine RTR Nachrichten. Meine sende Funktionen.

1
typedef struct {
2
  union {
3
    uint8_t data[8];
4
    struct {
5
      uint32_t low;  
6
      uint32_t high; 
7
    } words;
8
    uint16_t int_data[4]; 
9
    uint64_t _64Bit;
10
  };
11
} can_data_t;
12

13

14
typedef struct{
15
  CAN_TxHeaderTypeDef tx_header;
16
  CAN_RxHeaderTypeDef rx_header;
17
  CAN_HandleTypeDef *hcan;
18
  uint32_t mailbox[3];
19
  can_data_t rx;
20
  can_data_t tx;
21
  device_id_t *device_id;
22
}can_t;
23

24
void can_send_message(can_t *can, uint32_t identifier){
25
  can->tx_header.DLC = 8;
26
  can->tx_header.ExtId = 0;
27
  can->tx_header.IDE = CAN_ID_STD;
28
  can->tx_header.RTR = CAN_RTR_DATA;
29
  can->tx_header.StdId = identifier;
30
  can->tx_header.TransmitGlobalTime = DISABLE;
31
  HAL_CAN_AddTxMessage(can->hcan, &can->tx_header, can->tx.data, can->mailbox);
32
}
33

34
void can_send_rtr_message(can_t *can, uint32_t identifier){
35
   
36
    can->tx._64Bit = 0; 
37
    can->tx_header.DLC = 0;
38
    can->tx_header.ExtId = 0;
39
    can->tx_header.IDE = CAN_ID_STD;
40
    can->tx_header.RTR = CAN_RTR_REMOTE;
41
    can->tx_header.StdId = identifier;
42
    can->tx_header.TransmitGlobalTime = DISABLE;
43

44
   
45
    HAL_StatusTypeDef status = HAL_CAN_AddTxMessage(can->hcan, 
46
                                                    &can->tx_header,
47
                                                    can->tx.data,
48
                                                    &can->mailbox);
49

50
   
51
    if (status != HAL_OK) {
52
        // Fehlerbehandlung
53
        printf("Fehler beim Senden der RTR-Nachricht: %d\n\r", status);
54
        
55
    } else {
56
        printf("RTR-Nachricht erfolgreich gesendet: Identifier: %X\n\r",
57
               can->tx_header.StdId);
58
    }
59
}

Dann der Filter auf der Empfänger Seite.

1
void can_set_filter(can_t *can, uint16_t filter_id_high, uint16_t filter_mask_high, uint32_t filter_bank, uint32_t filter_mode, uint32_t fifo){
2
  CAN_FilterTypeDef sFilterConfig;
3
  sFilterConfig.FilterBank = 0;
4
  sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;
5
  sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
6
  sFilterConfig.FilterIdHigh = 0x50C<<5; 
7
  sFilterConfig.FilterIdLow = 0x0000;
8
  sFilterConfig.FilterMaskIdHigh = 0x50C<<5;
9
  sFilterConfig.FilterMaskIdLow = 0x0000;
10
  sFilterConfig.FilterFIFOAssignment = CAN_FILTER_FIFO0; //<- IST FIFO 0
11
   sFilterConfig.FilterActivation = ENABLE;
12

13
  if (HAL_CAN_ConfigFilter(&hcan, &sFilterConfig) != HAL_OK) {
14
    // Fehlerbehandlung
15
  }
16
}

Dieser Filter soll auf 0x50C filtern. Das klappt auch ganz gut wenn ich auf dem STM32F302R8 mit

1
can_send_message(&can, 0x050C);

eine Datennachricht sende. aber wenn ich eine RTR sende empfängt der Bluepill nichts. Im Augenblick nutze ich nur FIFO 0. Dies ist die Callback

1
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
2
{
3
  HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &can.rx_header, can.rx.data);
4
  //can_bridge(&can);
5
  printf("Is Request: %d\r\n", can.rx_header.RTR);
6
  printf("Filter Value: 0x%lX\r\n", can.rx_header.StdId);
7
  printf("Filter Match Index: 0x%ld\r\n", can.rx_header.FilterMatchIndex);
8
  for(int x=0;x<4;x++){
9
    printf("Data %d: 0x%X\r\n", x, can.rx.int_data[x]);
10
  }
11
  printf("###########STM32F103######00########\r\n");
12
  //can_send_id(&can);
13

14
}
OP #7689089
Lesenswert?

Habe eine Lösung gefunden. Man muss dem Filter sagen das er auch das RTR Bit prüfen soll. Ich habe meine can_set_filter angepasst.

1
void can_set_filter(can_t *can, uint16_t filter_id_high, uint16_t filter_mask_high, uint32_t filter_bank, uint32_t filter_mode, uint32_t fifo){
2
  CAN_FilterTypeDef sFilterConfig;
3
  sFilterConfig.FilterBank = filter_bank;
4
  sFilterConfig.FilterMode = filter_mode;
5
  sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
6
  sFilterConfig.FilterIdHigh = filter_id_high;
7
  sFilterConfig.FilterIdLow = 0x0002;
8
  sFilterConfig.FilterMaskIdHigh = filter_mask_high;
9
  sFilterConfig.FilterMaskIdLow = 0x0000;
10
  sFilterConfig.FilterFIFOAssignment = fifo;
11
  sFilterConfig.FilterActivation = ENABLE;
12

13
  if (HAL_CAN_ConfigFilter(&hcan, &sFilterConfig) != HAL_OK) {
14
    // Fehlerbehandlung
15
  }
16
}

Ich setzte sFilterConfig.FilterIdLow = 0x0002, da das RTR Bit das verletzte ist. Somit filtere ich auf den Identifier 0x50C, einmal als Daten Nachricht sFilterConfig.FilterMaskIdLow = 0x0000; und als RTR Nachricht mit sFilterConfig.FilterIdLow = 0x0002;.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren