GENMASK and FIELD_PREP macro can't get correct bits value of register

I use GENMASK and FIELD_PREP macro to get bits value of register. But it failed to get correct bits value.

#define LP5861_DEV_INITIAL_RESERVED_MSK      GENMASK(7, 3)
#define LP5861_DEV_INITIAL_RESERVED(x)       FIELD_PREP(LP5861_DEV_INITIAL_RESERVED_MSK, x)
#define LP5861_DEV_INITIAL_DATA_REF_MODE_MSK GENMASK(2, 1)
#define LP5861_DEV_INITIAL_DATA_REF_MODE(x)  FIELD_PREP(LP5861_DEV_INITIAL_DATA_REF_MODE_MSK, x)
#define LP5861_DEV_INITIAL_PWM_FRE_MSK       BIT(0)
#define LP5861_DEV_INITIAL_PWM_FRE(x)        FIELD_PREP(LP5861_DEV_INITIAL_PWM_FRE_MSK, x)
const uint8_t u8=0x5e;
devInit.reserved    = LP5861_DEV_INITIAL_RESERVED(u8);
devInit.dataRefMode = LP5861_DEV_INITIAL_DATA_REF_MODE(u8);
devInit.pwmFre      = LP5861_DEV_INITIAL_PWM_FRE(u8);

u8=0x5e
devInit.reserved=0xF0, devInit.dataRefMode=0x4, devInit.pwmFre=0x0

Parents Reply
  • snowuyl said:
    Thanks for your reply!

    No problem at all, we are happy to help!

    snowuyl said:
    Do you think it is helpful if I share whole project source code about this issue?

    No, I do not think so at this time.
    I am not familiar with the code you have shared in your ticket, but I see a reference to LP5861 which to my knowledge is a Texas Instrument LED driver. We only provide support for Nordic devices and code here on DevZone, and so if you require technical support with the driver for the LED driver chip you must reach out to Texas Instrument or whoever supplied the driver you are working with.

    Best regards,
    Karl

Children
Related