Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By mikekgr
#70792
tele_player wrote:That code sends 7 bits, MSB first.

yes for sure but as far as I can understand sends the bits: B8,B7,B6,B5,B4,B3,B2 correct?
I need to send the bits: B7,B6,B5,B4,B3,B2,B1
so possible I need something like the bellow, please confirm:
Code: Select allb <<= 1;
   for (int i = 0; i < 7; i++) { /// MODIFIED FOR 7 BITS ONLY ///
     digitalWrite(m_txPin, (b & 0x40) ? HIGH : LOW);   /// check the MSB each time and then serialize to m_txPin ///
     WAIT;
     b <<= 1;   // it is doing right shift
   }


Am I right?
Many thanks
User avatar
By mikekgr
#70795
tele_player wrote:No, you are incorrect.

For this discussion, think of bits in an 8-bit byte numbered b7 to b0, b7 is high bit.
My code uses 0x40 to select b6, loops 7 times, shifting left after sending each bit.
So, it sends b6-b5-b4-b3-b2-b1-b0.

Dear tele_player, I understood now. Actually I missed the point that you code
Code: Select alldigitalWrite(m_txPin, (b & 0x40) ? HIGH : LOW)
is pointing at the b6 ( 0x40 ) , I mistakenly thought that you are pointing at the b7...
As you can see I am very C newbie !
Thanks friend for all help given to me!