Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: 14-bit mark parity bit UART communication error

  1. #1

    14-bit mark parity bit UART communication error

    Hi, I can't seem to get this code working. Its aim is to be able to send 14-bit values via UART.

    Transmission is done in 4 steps.
    Step 1: Bitshift the whole unsigned integer left.
    Step 2: Divide the int and only bitshift the high byte left (<<)
    Step 3: Set high byte bit 0 to 1 to indicate transmission (since I shifted the whole variable previously, the low byte bit 0 cannot be 1)
    Step 4: Transmit high byte followed by low byte.

    void transmitUART1(unsigned int valueToTX1){
    valueToTX1<<1;
    highByteTX1=highByte(valueToTX1);
    lowByteTX1=lowByte(valueToTX1);
    highByteTX1<<1;
    bitSet(highByteTX1,0);
    Teensy_UART1.write(highByteTX1);
    Teensy_UART1.write(lowByteTX1);
    }

    The recieving of bytes is also done in 4 steps.
    Step 1: Receive high byte followed by low byte.
    Step 2: Bitshift the high byte right (>>).
    Step 3: Put bytes together in a word.
    Step 4: Bitshift the int (valueToRX1) right (>>).

    void receiveUART1(){
    if(Teensy_UART1.available()){
    if(transmission1){
    lowByteRX1=Teensy_UART1.read();
    valueToRX1=word(highByteRX1,lowByteRX1);
    valueToRX1>>1;
    transmission1=false;
    }else{
    highByteRX1=Teensy_UART1.read();
    if(bitRead(highByteRX1,0)){
    highByteTX1>>1;
    transmission1=true;
    }
    }
    }
    }

    Im not getting the result im looking for, whats wrong with my code?

    /Johan

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,456
    We generally expect you to show a complete program on this forum. When you post these sorts of code fragments, anybody wishing to help you has to guess many important details, like the types for your variables and what the difference between "Teensy_UART1" and something like "Serial1" might be.

    Please, don't make this a guessing game! Show a complete program. If your code is too large or has proprietary secrets, please put some work into composing a small but complete (and verified to reproduce the problem) program you can post here.

    Also, put the "code" tags around your code, so the white space shows correctly when people read your message. Look for this button when writing your message.

    Click image for larger version. 

Name:	sc.png 
Views:	46 
Size:	10.1 KB 
ID:	14506

  3. #3
    Senior Member
    Join Date
    May 2017
    Posts
    220
    If this is your real code, these statements don't do anything because there is no assignment ( no = ).

    valueToTX1<<1;

  4. #4
    rcarr thanks, the issue was indeed the missing "=" when bit shifting!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •