2023-04-24 07:53 AM - edited 2023-11-20 07:17 AM
I am using a the nucleo32 with a stm32F303K8 for my project. I am using arduino and creating a TCP modbus and RTU modbus server.<br>
I have set the pins as folows:
| Description | Type | Arduino | STM32 | Pin Number |
|--------------------|-----------|---------|-------|------------|
| Pulse input 1 | INTERRUPT | A0 | PA0 | 6 |
| Pulse input 2 | INTERRUPT | A1 | PA1 | 7 |
| Pulse input 3 | INTERRUPT | A7 | PA2 | 8 |
| Pulse input 4 | INTERRUPT | A2 | PA3 | 9 |
| Pulse input 5 | INTERRUPT | A3 | PA4 | 10 |
| Pulse input 6 | INTERRUPT | A4 | PA5 | 11 |
| Pulse input 7 | INTERRUPT | A5 | PA6 | 12 |
| Pulse input 8 | INTERRUPT | A6 | PA7 | 13 |
| MAX31865 DI | MOSI | D6 | PB1 | 14 |
| MAX31865 DO | MISO | D3 | PB0 | 15 |
| MAX31865 CLK | CLK | D9 | PA8 | 18 |
| MAX31865 CS 1 | OUTPUT | D10 | PA11 | 21 |
| MAX31865 CS 2 | OUTPUT | D2 | PA12 | 22 |
| MAX31865 CS 3 | OUTPUT | D5 | PB6 | 29 |
| MAX31865 CS 4 | OUTPUT | D4 | PB7 | 30 |
| MODBUS RTU TX | TX | D1 | PA9 | 19 |
| MODBUS RTU RX | RX | D0 | PA10 | 20 |
| DEBUG Serial TX | TX | -- | PA14 | 24 |
| Ethernet W5500 CS | OUTPUT | -- | PA15 | 21 |
| Ethernet W5500 SDI | MOSI | D11 | PB5 | 28 |
| Ethernet W5500 SDO | MISO | D12 | PB4 | 27 |
| Ethernet W5500 SCK | CLK | D13 | PB3 | 26 |
| Ethernet W5500 RST | NRST | -- | NRST | 4 |
| SWDIO | SWDIO | -- | PA13 | 23 |
| SWCLK | SWCLK | -- | PA14 | 24 |
I have set the Serial as folows:<br>
Serial.setTx(PA14);
Serial.setRx(PNUM_NOT_DEFINED);
Serial.begin(115200);
And the setting the interrupts:
pinMode(interruptPin1, INPUT_PULLUP);
pinMode(interruptPin2, INPUT_PULLUP);
pinMode(interruptPin3, INPUT_PULLUP);
pinMode(interruptPin4, INPUT_PULLUP);
pinMode(interruptPin5, INPUT_PULLUP);
pinMode(interruptPin6, INPUT_PULLUP);
pinMode(interruptPin7, INPUT_PULLUP);
pinMode(interruptPin8, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin1), interrupt1Callback, FALLING);
attachInterrupt(digitalPinToInterrupt(interruptPin2), interrupt2Callback, FALLING);
attachInterrupt(digitalPinToInterrupt(interruptPin3), interrupt3Callback, FALLING);
attachInterrupt(digitalPinToInterrupt(interruptPin4), interrupt4Callback, FALLING);
attachInterrupt(digitalPinToInterrupt(interruptPin5), interrupt5Callback, FALLING);
attachInterrupt(digitalPinToInterrupt(interruptPin6), interrupt6Callback, FALLING);
attachInterrupt(digitalPinToInterrupt(interruptPin7), interrupt7Callback, FALLING);
attachInterrupt(digitalPinToInterrupt(interruptPin8), interrupt8Callback, FALLING);
I have removed the SB2 solder brige from the NUCLEO.
Now 7 of the 8 inputs work as expected except PA2 (A7). Whenever this pin is triggered the program stops working.<br>
I would like to know why this pin is causing a crash?<br>
Could somebody explain why this is happening?
2023-04-24 09:07 AM
>>I would like to know why this pin is causing a crash? Could somebody explain why this is happening?
Use a DEBUGGER, and DEBUG it.
Stop the running code, see where/how it is stuck.
Use a Hard Fault Handler to output useful / actionable data if it gets stuck there.
Check the stack, registers, etc.
Check the EXTI IRQHandler, make sure the source is properly cleared, otherwise it will keep interrupting, and blocking foreground code execution.
2023-04-24 09:32 AM
>I am using arduino
so better you ask in arduino forum...
see:
+
>Use a DEBUGGER
2023-04-25 01:44 AM
I have written a simple program with just PA2 as interrupt.
#include <Arduino.h>
const int interruptPin1 = PA2;
uint16_t interruptNumber1 = 0;
void setup() {
Serial.setTx(PA14);
Serial.setRx(PNUM_NOT_DEFINED);
Serial.begin(115200);
delay(1000);
Serial.println("");
Serial.println("Booting DBMatic FMS v0.0.1");
Serial.print("Initializing pulse inputs... ");
pinMode(interruptPin1, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin1), interrupt1Callback, FALLING);
}
void loop() {
Serial.println("In the main loop");
delay(1000);
}
void interrupt1Callback()
{
interruptNumber1++;
Serial.print("The number of interrupts of the PA2 pin are: ");
Serial.println(interruptNumber1);
}
The same issue occurred when i ran this code.
I have used STM32CUBEide to try and get the interrupt to work. But i can not get the serial to work on the PA14 pin
2023-04-25 05:29 AM
Just look at the schematic. PA2 is connected to STLink VCOM TX, PA14 is SWCLK. You cannot reasonably use these pins without changing board configuration (solder bridges).
2023-04-25 05:38 AM
Hello i have removed the SB2 connection to sever the PA2 pin from the VCP_TX pin before testing the code. And i am getting UART output. The serial output stops when the Interrupt is triggered
2023-04-25 11:31 PM
In real word, serial output should not be called from an interrupt service routine. If you desperately want to do it, then do not call serial output from loop().
Maybe it's time to grow up and dump Arduino environment?