2011-04-20 01:48 AM
Word Alignment Issue
2011-05-17 05:32 AM
''Can someone explain how to the 14bits is alligned in the 16bit word?''
No - because you have not mentioned what compiler you're using! This stuff is entirely compiler-dependent!''How can i assign these 14bits to the 14bit field'' Just do it ''manually'' with the normal 'C' shift and mask operators! It is unlikely that using bitfileds will gain you any advantage, and you have already seen that it brings in plenty of issues...!
2011-05-17 05:32 AM
2011-05-17 05:32 AM
You usually want to avoid bitfields because they give you no guarantees on alignment and padding.
<<, >>, &, |, and ~ are your friends2011-05-17 05:32 AM
''As all the registers on my DAC chip are 24bits long, it therefore seemed the logical approach to use bitfields.''
In theory, perhaps. But, in practice, 'C' bitfields are so compiler-dependent that it's not worth the effort - and there's unlikely to be any benefit anyhow.''I ideally want my 14bit word to sit right-alligned (ie in bits 13:0). Can you give code example of how you would extract this from an uint16_t and assign to data_u16 field please?'' Example of what, exactly?Why would there be any need to ''extract'' anything?
You just ignore the excess bits... Are familiar with the standard bitwise operators, and the shift operators, in 'C'...?