View previous topic :: View next topic |
Author |
Message |
[email protected]
Joined: 07 May 2017 Posts: 2
|
PIC24F Restart on float print |
Posted: Sun May 07, 2017 12:42 pm |
|
|
I am using compiler version 5.025. I am having an issue that when I print a float value on uart and the interrupt is on, the controller restarts. I have no idea why is this happening. Can anyone help me? I am using fprintf for printing on uart. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sun May 07, 2017 12:52 pm |
|
|
We are not mind readers, please post your code. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
[email protected]
Joined: 07 May 2017 Posts: 2
|
|
Posted: Sun May 07, 2017 12:59 pm |
|
|
Code: |
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES NOOSCIO
#FUSES SOSC_DIG
#pin_select U2TX=PIN_D0
#pin_select U2RX=PIN_D11
#use rs232(UART2, baud=9600, errors, BITS =8, stream=UART_GPS)
enable_interrupts(INT_TIMER1);
enable_interrupts(INTR_CN_PIN | BUTTON);
enable_interrupts(INTR_GLOBAL);
enable_interrupts(INT_RDA2);
float64 test_f = 3334.2313457;
while(1)
{
delay_ms(500);
fprintf(UART_BT," float OK %5.8f\r", test_f);
} |
Following is the output:
âBoot UART_BT OKf
float 3334.23134569
float 3334.23134569
float 3334.23134569
float 3334.23134569
float 3334.23134569
float 3334.23134569
float Boot UART_BT OKf
float 3334.23134569
float 3334.23134569
float 3334.23134569
float 3334.23134569
float 3334.23134569
float 3334.23134569
float Boot UART_BT OKf
float 3334.23134569
float 3334.23134569
When I comment enable_interrupts it works fine. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Sun May 07, 2017 1:19 pm |
|
|
Increase your stack size.
Float printf, uses a lot of stack.
#BUILD(STACK = 0x200)
If you did some diagnostics, you will almost certainly find that it is a stack overflow triggering the reset. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Sun May 07, 2017 1:47 pm |
|
|
That can't be your real 'test' program, as it has FOUR interrupts enabled and NONE have handlers (code) to deal with them. Also no device header or use clock and the printf format code appears to be wrong (though the compiler fixed it ?) |
|
|
|