Hi,
Am using an LPC2148 controller with the MCP2515 CAN_IC connected via the SPI. With the CAN_IC I'm supposed to read the TX-Control registers and RX-Control registers to set / read the status of the transmissions.
For this I have defined a struct as follows
struct txbNctrl_struct { int txpri:2; //0:1 //transmit priority bits int void2:1; //2 int txreq:1; //3 //transmit request status (clear to request message abort) int txerr:1; //4 //transmission error detected int mloa:1; //5 //message lost arbitration int abtf:1; //6 //message was aborted / or transmitted succesfully int void7:1; //7 };
in the main loop, I declare the struct as follows
struct txbNctrl_struct txb0ctrl,txb1ctrl,txb2ctrl; // one for each of the 3 transmit buffers
Now my problem is that, am not able to read the value from the MCP2515 as a whole byte say I get an error "error:incompatible types in assignment" for the following statements
txb0ctrl=mcp2515_read(TXB0CTRL); txb1ctrl=mcp2515_read(TXB1CTRL); txb2ctrl=mcp2515_read(TXB2CTRL);
where the TXB0CTRL,TXB1CTRL,TXB2CTRL are the addresses of the respective registers in the CAN_IC.
This code was used successfully used using the PIC microcontrollers and their compilers.
How should I modify my code with regard to Keil gcc compiler?
Ok. My question is that the C language supports the code I'd posted earlier with CCS compiler. Is there any kind of special rules I need to be following with the Keil gcc. If so, could you post the link for the same.
I have re-posted my code here for your reference.
struct txbNctrl_struct { int txpri:2; //0:1 //transmit priority bits int1 void2:1; //2 int1 txreq:1; //3 //transmit request status (clear to request message abort) int1 txerr:1; //4 //transmission error detected int1 mloa:1; //5 //message lost arbitration int1 abtf:1; //6 //message was aborted / or transmitted succesfully int1 void7:1; }; struct txbNctrl s_TXB0CTRL,s_TXB1CTRL,s_TXB2CTRL; s_TXB0CTRL=mcp2510_read(TXB0CTRL); s_TXB1CTRL=mcp2510_read(TXB1CTRL); s_TXB2CTRL=mcp2510_read(TXB2CTRL);
The C language just doesn't support assign of an integer to a struct - only to an individual member of the struct.
If you then spend time with the C language standard, then you might be able to figure out a number of work-arounds - like playing with unions or pointers. Or consider not using bit fields - because bit fields still means you need to make multiple assigns to a struct before you can assign the contents of that struct (once more requiring trickery) back to a register.
What you gain by playing with bit fields is lost by the extra hardship of trying that struct of bit fields to look like an integer.