-->
Page 4 of 5

Re: send out ascii characters to bit stream using a GPIO pin

PostPosted: Mon Oct 09, 2017 11:46 pm
by mikekgr
tele_player wrote:I don't want to get into figuring out what version you have installed, and I don't know what may or may not have changed, but here's the relevant function grabbed from somewhere on Github.
I've added comments showing what I changed to transmit 7 bits, no start, no stop. My comments will start with ***

Caveat: I haven't compiled this, or tested it, and I have little confidence that this will be of any use to you.

Code: Select all
size_t SoftwareSerial::write(uint8_t b) {
   if (!m_txValid) return 0;

   if (m_invert) b = ~b;
   // Disable interrupts in order to get a clean transmit
   cli();
   if (m_txEnableValid) digitalWrite(m_txEnablePin, HIGH);
   unsigned long wait = m_bitTime;
   digitalWrite(m_txPin, HIGH);
   unsigned long start = ESP.getCycleCount();
    // Start bit;
//   digitalWrite(m_txPin, LOW);   // *** disable START bit
//   WAIT;          // *** disable START bit
   for (int i = 0; i < 7; i++) {.  // *** Was 8
     digitalWrite(m_txPin, (b & 1) ? HIGH : LOW);
     WAIT;
     b >>= 1;
   }
   // Stop bit
//   digitalWrite(m_txPin, HIGH);  // *** disable STOP bit
//   WAIT;   // *** disable STOP bit
   if (m_txEnableValid) digitalWrite(m_txEnablePin, LOW);
   sei();
   return 1;
}


Dear tele_player,
thanks a lot for the modification! I will be able to test it after 10 hours approximately and I will let you know !

Re: send out ascii characters to bit stream using a GPIO pin

PostPosted: Tue Oct 10, 2017 1:51 pm
by mikekgr
mikekgr wrote:
tele_player wrote:I don't want to get into figuring out what version you have installed, and I don't know what may or may not have changed, but here's the relevant function grabbed from somewhere on Github.
I've added comments showing what I changed to transmit 7 bits, no start, no stop. My comments will start with ***

Caveat: I haven't compiled this, or tested it, and I have little confidence that this will be of any use to you.

Code: Select all
size_t SoftwareSerial::write(uint8_t b) {
   if (!m_txValid) return 0;

   if (m_invert) b = ~b;
   // Disable interrupts in order to get a clean transmit
   cli();
   if (m_txEnableValid) digitalWrite(m_txEnablePin, HIGH);
   unsigned long wait = m_bitTime;
   digitalWrite(m_txPin, HIGH);
   unsigned long start = ESP.getCycleCount();
    // Start bit;
//   digitalWrite(m_txPin, LOW);   // *** disable START bit
//   WAIT;          // *** disable START bit
   for (int i = 0; i < 7; i++) {.  // *** Was 8
     digitalWrite(m_txPin, (b & 1) ? HIGH : LOW);
     WAIT;
     b >>= 1;
   }
   // Stop bit
//   digitalWrite(m_txPin, HIGH);  // *** disable STOP bit
//   WAIT;   // *** disable STOP bit
   if (m_txEnableValid) digitalWrite(m_txEnablePin, LOW);
   sei();
   return 1;
}


Dear tele_player,
thanks a lot for the modification! I will be able to test it after 10 hours approximately and I will let you know !

Dear tele_player,
there is a problem in the above modification. From each byte that I want to serialize bit by bit, it is necessary the compliance of the following rules:
1) Each byte should be serialize from MSB(Bit 8) to LSB(Bit 0) so right shifting is necessary
2) Bit 8 ( The most significant bit should be throw out ( discard it ) because our valuable bit information are 7 bits not 8 bits
3) to get a better understanding the byte that consisting of 8its should go out ( serialize as ):
bit(8) discard it{ First bit of the right bit shifting }
bit(7) first usable bit should serialize as "bit(1)"
bit(6) second usable bit should serialize as "bit(2)"
bit(5) third usable bit should serialize as "bit(3)"
bit(4) fourth usable bit should serialize as "bit(4)"
bit(3) fifth usable bit should serialize as "bit(5)"
bit(2) sixth usable bit should serialize as "bit(6)"
bit(1) seventh usable bit should serialize as "bit(7)"
What do you think? How can the softwareserial routine should be modified in order to fullfill the above requirements?

Thanks and Best Regards,
Mike Kranidis

Re: send out ascii characters to bit stream using a GPIO pin

PostPosted: Tue Oct 10, 2017 2:19 pm
by tele_player
That requires a small change to two lines:

Code: Select all   for (int i = 0; i < 7; i++) {.  // *** Was 8
     digitalWrite(m_txPin, (b & 0x40) ? HIGH : LOW);   // ***
     WAIT;
     b <<= 1;   // ***
   }

Re: send out ascii characters to bit stream using a GPIO pin

PostPosted: Tue Oct 10, 2017 3:20 pm
by mikekgr
tele_player wrote:That requires a small change to two lines:

Code: Select all   for (int i = 0; i < 7; i++) {.  // *** Was 8
     digitalWrite(m_txPin, (b & 0x40) ? HIGH : LOW);   // ***
     WAIT;
     b <<= 1;   // ***
   }

Perfect!!!
I can test it tomorrow, of course I will reported back.
What about the discarding of the 8bit at first?
Thanks a lot dear tele_player for all of your kind help and contribution.

Best Regards,
Mike Kranidis