Hello,
I am working with serial communication interrupt in LPC1768. In that I am receiving a three parameter data in the form of string as X:2341Y:114Z:75 via serial interrupt.
After receiving I am splitting this string and storing 2341 in array1[],114 in array2[] and 75 in array3[] and converting into integer and using in the main function as follows.
int main(){ .... .... .... while(1){ cut_count = (((int)(cut_preset_value[0]-0x30)*1000)+((int)(cut_preset_value[1]-0x30)*100)+((int)(cut_preset_value[2]-0x30)*10)+((int)(cut_preset_value[3]-0x30))); duty_count = (((int)(duty_cycle_value[0]-0x30)*10)+((int)(duty_cycle_value[1]-0x30))); TOTAL_TIME = ceil((ONE_MIN_IN_MSEC)/(cut_count)); //ceil func. is to round off the value dividend_value = ((TOTAL_TIME)*(duty_count)); ON_TIME_VALUE = ceil(dividend_value/PERCENT_DIVISOR_VALUE); //ceil func. is to round off the value OFF_TIME_VALUE = ceil(((TOTAL_TIME)-(ON_TIME_VALUE))); //ceil func. is to round off the value
} }
Note:Here cut_preset_value[],suction_preset_value[] and duty_cycle_value[] are the three globally defined arrays for storing values.
Within the while loop the arrays are not updating without board reset.
kindly provide some solution for this. Thank you.
The code fragment that we see doesn't tell is if you have made the arrays volatile, i.e. telling the compiler that the contents may be modified asynchronously.
The code fragment doesn't show that you have any form of synchronization to make sure that the four bytes of the array are actually from the same transfer, and you don't happen to compute values in the middle of a transfer.
Forgot to mention - the code in your loop seem to assume that the arrays contains valid ASCII digits, i.e. characters between '0' and '9' - how do you know that is true? Do you have any intelligence in your ISR? What happens if you get a transfer error, or misses the synchronization?
"code fragment doesn't tell is if you have made the arrays volatile"
Yes I used to check with the arrays which is defined,but it also doesn't works.
And an error is arising for the case of ascii-to-integer conversion using "atoi function" if I use volatile array as argument instead of const char *str.
Vignesh
"how do you know that is true? Do you have any intelligence in your ISR?"
I am using timer interrupt also and timer count is incremented for every millisecond in timer interrupt routine.
I am using that ON_TIME_VALUE and OFF_TIME_VALUE as a conditional value for switching ON or OFF the relay as follows.
if(count == ON_TIME_VALUE) { LPC_GPIO1->FIOCLR |= (1<<8); //LPC_GPIO1->FIOSET |= (1<<9); } if(count == TOTAL_TIME) { //LPC_GPIO1->FIOCLR |= (1<<9); LPC_GPIO1->FIOSET |= (1<<8); count=0; }
Its surely working for the first time value replace process and not on further..