AnsweredAssumed Answered

S12ga48 code hangs in for(;;) loop.

Question asked by Nandulal Gavali on Feb 15, 2017
Latest reply on Feb 24, 2017 by Radek Sestak

Hello All,

I am designing the data acquisition system on S12GA48 (LQFP48 pin). In my system, I have to display data on 20x4 char LCD. I am taking data from other 27 modules on CAN bus @37ms rate every-time. Also, I am sending data to GSM modem every 1 second. I have 1 timer compare ISR for 35ms. In that ISR, I am getting data on CAN from other modules. Apart from it, I have I2C based RTC, SPI based EEPROM , I2C based Humidity sensor and using MODBUS protocol on RS485. My LCD operating is 4 bit mode. I am doing I2C and SPI based PORT bit banging. I am using Codeworrior 5.2 version. My infinite loop look like,








Timer ISR is,


void HeartBit_ISR (void)
static uCHAR cntDecodeMODBUS = 0;
static uCHAR cntADCrefresh = 0;
static uCHAR cntSlaveRead = 0;
volatile uINT batPackVolt = 0;

// Get the errors


if(++cntADCrefresh > timeADCrefresh) // Excution - 100us
cntADCrefresh = 0;
flagADCsample = TRUE;

// Add all the voltages to create the Pack voltage
readAllADCs(); // Sample ADC for 100 ms time

// TimeOut for the MODBUS if no communication in 150ms then clear Buffer
if((++comTimeOut > 5) && (flagSerialReceive)) // Code takes 100uS time
comTimeOut = 0;
flagDecodeMODBUSFrame = 0;
flagSerialReceive = 0;

// Slave Sample after every 37ms So, All slave can update data in 1sec
flagCANsendCmd = TRUE;


I am using isolated USBDM (based on pgo design) for the debugging and programming which I have created and is working fine.


My LCD paging code is,


void LCDdisplayRefresh (void)

// Select different Displays @4sec rate

// Increase display counter
dispCounter = (dispCounter + 1);

// Total Five display pages
if(dispCounter > (MAX_LCD_PAGES-1))
dispCounter = START_LCD_PAGE;

if(dispCounter == 0)
displayVolt1PAGE(); // display page 1

if(dispCounter == 1)
displayVolt2PAGE(); // display page 2

if(dispCounter == 2)
displayVolt3PAGE(); // display page 3

if(dispCounter == 3)
displayVolt4PAGE(); // display page 4

if(dispCounter == 4)
displayVolt5PAGE(); // display page 5

if(dispCounter == 5)
displayVolt6PAGE(); // display page 6

if(dispCounter == 6)
displayCurrPAGE(); // display page 7

if(dispCounter == 7)
displayCurr2PAGE(); // display page 8

if(dispCounter == 8)
displayErrAlramPAGE(); // display page 9 


Initially, I used 'switch case loop' but shifted on 'if loop' to check whether loop is doing some malfunction. I found that somehow my code going either out of infinite loop or stuck to somewhere in the other function and it stops LCD refreshing and hold any of the LCD page. I also tried to hot sync USBDM to find out the issue.


But whenever I connect USBDM, the code recovers and started again. I do not understand how I can check what is happening there. I have assigned the stack to 0x150  bytes and found that only half of this value being used during continuous operation. So, this is not looking as a stack failure issue.


Also, I found that all my interrupts are working fine at all times. I have disable all optimization in standard setting. I cannot share all my code due to security reqasons. Can anyone suggests me what can I do to check what is happening there?



N.K. Gavali