Dali on MCU

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Dali on MCU

1,221 次查看
Chish
Contributor II

Hi, I'm currently sending hours to Dali Master by breaking it down to 1 byte and sending LSB, MIDB, and MSB. I've attached the picture of my code. the stunden(hour) value is 324. But my logic doesn't work. 

I used two logics

Picture mark with 1 is for 3 or higher digits and it doesn't work. When I used the commented part for two digit it works fine but not for 3 digits and above.

Can somebody help me out that what could be the problem in my code? How can I separate the 324 to MSB=3, MIDB=2, LSB=4

Chish_0-1635948068707.png

 

标记 (1)
0 项奖励
回复
1 回复

1,180 次查看
PabloAvalos
NXP TechSupport
NXP TechSupport

Hi @Chish 

Many thanks for your patience.

Regarding your question about "what could be the problem in your code", as I can see, you are probably missing to divide by 100 in the MSB, so, "how can you separate the 324 to MSB=3, MIDB=2, LSB=4" , we would like to suggest you this code snippet that you might use in your code:

 

void stunden (uint32_t hour, uint8_t bit);

 

typedef struct{

uint8_t msb;

uint8_t midb;

uint8_t lsb;

}stunden_t;

 

stunden_t g_stunden;

 

void stunden (uint32_t hour, uint8_t bit)

{

switch (bit)

{

case QUERY_STUNDEN_MSB:

hour /= 100;

g_stunden.msb = hour;

break;

 

case QUERY_STUNDEN_MIDB:

hour /= 10;

g_stunden.midb = hour % 10;

break;

 

case QUERY_STUNDEN_LSB:

g_stunden.lsb = hour % 10;

break;

 

default:

break;

}

return;

}

 

And then you can use this function like this:

 main.c :

stunden(324, QUERY_STUNDEN_LSB);

stunden(324, QUERY_STUNDEN_MIDB);

stunden(324, QUERY_STUNDEN_MSB);

 

So this function can return the value that you want for 3 digits, and for 3+ digits you may add to the function the other cases dividing the hour by 1000, 10,000, and so on.

 

If you require more assistance, we would be glad if you let us know.

 

Best Regards.

Pablo Avalos.

0 项奖励
回复