Ray Hall

Member since: Saturday, 07 July 2018
Last login: 5 months ago
Profile viewed: 85 views

No Rank
Points: 0

Ray Hall created a new topic ' Approving Posts' in the forum. 5 months ago

Hello,

Why does it take days for a post to be approved by a moderator. Also why does it have to be approved when you have posted before. I have been posting on the forum for years. Why now do I have to be approved.

Ray.

Read More...

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

I said I would report what was the cause. Here it is.

NXP/Freescale.

Your struct initializer doesn't match your struct. Missing curly brackets around struct array initializer part, also missing brackets around struct array struct-element. Only first array element gets initialized.

I replied.

"I would have thought the compiler would have given an error or warning"

NXP/Freescale

I tried with different and much more modern C99 compiler for different architecture, no warning either. Remove array of structs member and both start complaining about extra data. Yet another C compiler oddity..

So now all solved. My coding fault and no compiler warning of my error. This caused all the confusion as to where the finger should be pointed. Not in Embarcadero's direction...

Ray.

Read More...

Ray Hall replied to the topic 'Question about #pragma pack(push, 1)' in the forum. 5 months 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. 5 months 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. 5 months 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...