cancel
Showing results for 
Search instead for 
Did you mean: 

How to store 8 bits register value from Modbus to different variable

Lchal.1
Associate II

Hi, I want to store 8 bits of data coming from my Modbus in a different variables in the form of 1's and 0's using stm32f103.

I have done code like , the bits i have sent is 101101101 sent by Modbus is storing in my holding register [1] in the form of decimal value. can I convert it to binary format . if so how can I store it. if i am capable of storing binary bits in my holding registers[0] = 101101101. then is it possible to store bit by bit value in another variables like a = 1, b=0, c = 1, d = 1, e = 0 , f =1 so on.

but I am confused how to do it can anyone help me with it please .

control register = holding registers[0]; // Modbus value storing

motion_ type_ absolute  =  (control_ registers>>1) & 1 ;

stop_ movement = (control_ registers>>2) & 1;

kill_ motion = (control _registers>>3) & 1;

Enable_ Disable_ drive= (control_ registers>>4) & 1;

Reset_ Drive = (control_ registers>>5) & 1;

Home _Drive = (control _registers>>6) & 1;

jog = (control _registers>>7) & 1;

Jog _neg = (control_ registers>>8) & 1;

this is the code or what i need to do please help me with it.

Thank You

2 REPLIES 2
KnarfB
Principal III

The code looks good execpt that the bits (shifts) range from 0 to 7, not 1 to 8.

i tried but the bits are not storing properly. can anyone help me with this please.

Thank you