Ray Hall

Member since: Saturday, 07 July 2018
Last login: 1 week ago
Profile viewed: 31 views

No Rank
Points: 0

Ray Hall replied to the topic 'Question about #pragma pack(push, 1)' in the forum. 1 week ago

Ted,
Any 16bit values sent from the micro have to have their bytes swaped. It is a bit of a pain, but I have a function I call to do that.

I found that when I made four seprate groups of values the data was correct, Example...

uint8_t enabled_frame1;
uint8_t rate_frame1;
uint16_t id_frame1;
uint8_t byteOrder_frame1;
uint8_t data[8]_frame1;

uint8_t enabled_frame2;
uint8_t rate_frame2;
uint16_t id_frame2;
uint8_t byteOrder_frame2;
uint8_t data[8]_frame2;

etc....

Based on this I desided the problem was Freescale's.

After I get a responce from them I will post what they said.

Ray.

P.S. rather then selecting the code text and clicking the code icon I just typed in the code word brackets on each end. Not sure if that is a work around, but worked for me.

Read More...

Ray Hall replied to the topic 'Question about #pragma pack(push, 1)' in the forum. 2 weeks ago

Hello Ted, I found the problem. It was not C++ Builder it was the Freescale (NXP) compiler/linker. It did not like the frame[] array. Changed it so there was four sets of values with unique names and now get useful values when transferred into the PC program.

Thank you.
Ray.

Read More...

Ray Hall created a new topic ' Question about #pragma pack(push, 1)' in the forum. 2 weeks ago

I am currently using #pragma pack(push, 1) and #pragma pack(pop) before and after a structure statement. This has worked well for me in the past. I now am getting incorrect values when reading the structure value. I believe the problem is the use of the frame[4] structure array. I have not done this in the past.

Am I using the correct pragma pack settings.

#pragma pack(push, 1)  

   struct CanBusSettings {
          uint8_t startChar; // $ Start character
          uint8_t PacketHi;
          uint8_t PacketLo;
          uint8_t PacketID;
          uint8_t freq;
          uint8_t busEnabled;
          uint8_t readCanData;
          uint16_t readID;
         struct FrameSettings {
             uint8_t enabled;
             uint8_t rate;
             uint16_t id;
             uint8_t byteOrder;
             uint8_t data[8];
         }frame[4];
    }can;

  #pragma pack(pop)


Read More...