This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

spiDAT1_t and C++ problem

Other Parts Discussed in Thread: HALCOGEN

If I am mixing C++ and C code and using spiDAT1_t from C++ code, the CS_HOLD and WDEL are 1 Byte long, in C code they are 4 Bytes long.

That brought problems with configuration of CSNR. How to avoid this?

Thomas

typedef struct spiDAT1RegConfig
{
    boolean CS_HOLD;
    boolean WDEL;
    SPIDATAFMT_t DFSEL;
    uint8 CSNR;
}spiDAT1_t;

  • Hello Thomas,

    In Halcogen we handle this be simple bit manibulations. i.e., we define the address and then write 32 bits at a time to the register.

    However, prior to having Halcogen, we had some standard header files that defined the registers as unions. Below is the union we used to define the SPIDAT1 register. Note that the use of Unions is not accepted/advised under some safety guidlines such as MISRA C.

     union                                      /* 0x3C      */
        {
         unsigned int SPIDAT1_UL; 
         struct
         {
         unsigned int : 3; 
         unsigned int CS_HOLD_B1: 1;
         unsigned int : 1; 
         unsigned int WDEL_B1: 1;
         unsigned int DFSEL_B2: 2;
         unsigned char CSNR_UC;
         unsigned short SPIDAT1;
         }SPIDAT1_ST;
        }SPIDAT1_UN;