I am using the SPI to access a couple of 20 & 24 bit A/D converters which have some digital status bits preceding the reading. I already have some C code written (for another CPU) that defines the incoming data structure as a unsigned long. The Keil compiler, however, says I must use char or integer size bit fields. Is there an easy way around this without having to hand code the byte manipulation code manually?
I'm not sure I properly understand this question. If I do, a union in which one member is an unsigned long, and the other is a struct containing unsigned chars and bit fields may solve your problem. I never use bit fields for this sort of thing, because the way bit fields map onto bytes is implementation-dependent, and may even change from one version of a compiler to the next, or with different compiler option settings. -- Gary Culp
Here is a simplified example.
typedef struct { unsigned long det_in :4, /*compliance & short detection bits */ Brd_rev :4, /* board / pal revision */ nu :4, /* not used as of 8/2000 */ AD_data :20; /* 0=-max, 0x80000=0v, fffff=+max */ } Bridge_brd_Rx_Type; /* for each bridge card */
{ long reading; char revision; reading = Brdg1.AD_data; revision = Brdg1.Brd_rev; ... }