|
|
View previous topic :: View next topic |
Author |
Message |
NRodriguez
Joined: 09 Oct 2011 Posts: 2
|
Struct alignment |
Posted: Sun Oct 09, 2011 1:10 pm |
|
|
Hi Everyone
I've been searching in the help of the CCS help and user guides and in this forum but I haven't found anything about how the structs are aligned in CCS.
My interest is because I have some structures with bitfields of different lengths that must be sent though serial port and CAN, and I need the fields not to be padded to byte alignment, to agree some standard. Does CCS pack the structs or it keeps aligned to byte? If I can configure the alignment, how can I do it?
I'm working with PCH v4.038 to some PIC18f4680. _________________ Nestor Rodriguez Perez |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sun Oct 09, 2011 1:46 pm |
|
|
Structures in CCS, by nature, are byte sized. Depending on the number of bits you must send, you could create a variable larger then the number of bits you need. Say 'int16 my16bits' for up to 16 bits of data, int32 my32bits for up to 32 bits. Create a structure that allows bit access to 'my16bits'. When you need to transmit the data, simply increment a 'bit counter' and test the bit then set/reset an I/O port line as required. IF you only need bits 3 thru 14, code for (counter=3,<15,counter++). There are examples/drivers of using external EEPROMs in the examples folder. They may shed some light on another way to do it.
As for sending data to a 'serial port', if you mean 'PC comport', they are usually configured for 8 bits( 1 byte) but can be 5-8 bits in length.
As for CAN, I'm not using it, so cannot comment on data structures for that.
You don't say what kind of datarate you need, etc. (what's on the other end ???) More information might be helpful. I have done 22bit serial datastreams in the past though it's probably easier to just use 3 bytes IF you're in control of both ends of the wire! |
|
|
NRodriguez
Joined: 09 Oct 2011 Posts: 2
|
|
Posted: Sun Oct 09, 2011 2:38 pm |
|
|
As I understand, temtronic, that means that even if you declare a field of 1 bit size, it will take 8 bits in memory, and that there is no way to change that.
Well, thanks for the info anyway.
About mapping the fields of the struct into a single variable, this is the way I was doing till now, but as I'm trying to develop an API following a standard which defines network protocols and allowed messages with their bitfields, so I must find a workaround to that problem to present valid arguments to whoever connects with my system.
More Info: The serial baudrate is 9600 Bauds, but there's no problem there because I control both sides of the link. I also control the CAN bus, but I should not make a link-dependent code for the API to follow the standard. So the parameters are not (or must not be) relevant for the implementation and for this question. _________________ Nestor Rodriguez Perez |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Oct 09, 2011 3:00 pm |
|
|
If you show us an coding example of what you want to do, I think we
could understand it better and maybe give a solution.
Preferably, post a complete small test program, so we can see it all:
structures, bitfields, serial transmission, etc. But make it be really
stripped down to have the absolute minimum amount of code necessary
to show the problem. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|