I have defined a global array in main.c:
__IO uint8_t data[3]={0,0,0};
then, I extern and assign vlues to this array in another c file:
extern __IO uint8_t *data;
INTERRUPT_HANDLER(EXTI_PORTB_IRQHandler, 4){
if(GPIO_ReadInputPin (GPIOB, GPIO_PIN_0) == SET)
data[0] = 1;
if(GPIO_ReadInputPin (GPIOB, GPIO_PIN_1) == RESET);
data[1] = 0;
if(GPIO_ReadInputPin (GPIOB, GPIO_PIN_1) == SET)
data[1] = 1;
if(GPIO_ReadInputPin (GPIOB, GPIO_PIN_2) == RESET);
data[2] = 0;
if(GPIO_ReadInputPin (GPIOB, GPIO_PIN_2) == SET)
data[2] = 1; }
the problem is that I can not change the value of 'data'(I get the vaule through debug mode of IAR using J-link).If I define this array as local variable I can change the value:
__IO uint8_t data[3]={0,0,0};
INTERRUPT_HANDLER(EXTI_PORTB_IRQHandler, 4){
if(GPIO_ReadInputPin (GPIOB, GPIO_PIN_0) == SET)
data[0] = 1;
if(GPIO_ReadInputPin (GPIOB, GPIO_PIN_1) == RESET);
data[1] = 0;
if(GPIO_ReadInputPin (GPIOB, GPIO_PIN_1) == SET)
data[1] = 1;
if(GPIO_ReadInputPin (GPIOB, GPIO_PIN_2) == RESET);
data[2] = 0;
if(GPIO_ReadInputPin (GPIOB, GPIO_PIN_2) == SET)
data[2] = 1; }
in the past time, I define a global variable not an array and I can extern change the value in another file. so, what is the difference between a vriable and array used as globle ones?
volatile
? If not, you will need that on any variable you access from both normal and interrupt threads. – Chris Stratton May 14 at 14:54