Dear board Im writing a driver for HX711 load cell pickup unit.
This has a clock pin which is input to hx711 ic and this clk will be driven by stm32f103 And a Dout pin where for every low to high transition hx711 will out a bit and this goes 24 bit long..
I need to read this serial input and store to a byte which is 24 bit data where i can use array of 3 bytes..
I can easily read input status low or high from input function.
But how can i assign that bit value to a byte at particular position??
Earlier in pic micro.. i have function called bit_set and bit_clear to set or clear particular bit in a byte...
I googled and found there are no code fullfilling my requirements.
Can anyone suggest me please?? I need to read pin and save 24 bit info and convert to decimal.
Thanks
And what do you think that code actually does?
Most likely, your problems with debugging are because it does not do anything useful at all - so the compiler just optimises it all away completely!
function called bit_set and bit_clear to set or clear particular bit in a byte
#include <stdio.h> #include <stdint.h> uint8_t bit_set( uint8_t data, int position ) { data |= (1u<<position); return data; } uint8_t bit_clear( uint8_t data, int position ) { data &= ~(1u<<position); return data; } void main(void) { printf( "%X\n", bit_set( 0x0, 0 ) ); printf( "%X\n", bit_set( 0x0, 1 ) ); printf( "%X\n", bit_set( 0x0, 2 ) ); printf( "%X\n", bit_set( 0x0, 3 ) ); printf( "%X\n", bit_clear( 0xFF, 0 ) ); printf( "%X\n", bit_clear( 0xFF, 1 ) ); printf( "%X\n", bit_clear( 0xFF, 2 ) ); printf( "%X\n", bit_clear( 0xFF, 3 ) ); }
#include <stdio.h> #include <stdint.h> uint8_t bit_set( uint8_t data, int position ) { data |= (1u<<position); return data; } uint8_t bit_clear( uint8_t data, int position ) { data &= ~(1u<<position); return data; } void main(void) { uint8_t Target = 0xC9; printf( "%X\n", Target ); Target = bit_set( Target, 1 ); Target = bit_clear( Target, 3 ); printf( "%X\n", Target ); }