Rustum
Newbie level 4
Hi All,
I am trying to access a port pin using bit-field structure.I do not have very much expertise in embedded C. All I am doing is below.Please advice.
The problem is Cortex-M4 CPU is going to an infinite interrupt handler loop when it hits the statement "pReg->bits.bit1 = 0;"
What am I doing wrong? Is it write way to access a hardware register and modify using structure and union?Please help.
I am trying to access a port pin using bit-field structure.I do not have very much expertise in embedded C. All I am doing is below.Please advice.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 typedef union { unsigned char Byte; struct { unsigned char bit0 : 1; unsigned char bit1 : 1; unsigned char bit2 : 1; unsigned char bit3 : 1; unsigned char bit4 : 1; unsigned char bit5 : 1; unsigned char bit6 : 1; unsigned char bit7 : 1; }bits; }registerType; int main(void) { registerType *pReg = ( registerType*)0x40040200;// port register address pReg->bits.bit1 = 0x00; pReg->bits.bit6 = 0; for(;;) { /* Place your application code here. */ } }
The problem is Cortex-M4 CPU is going to an infinite interrupt handler loop when it hits the statement "pReg->bits.bit1 = 0;"
What am I doing wrong? Is it write way to access a hardware register and modify using structure and union?Please help.
Last edited by a moderator: