Port Manipulation MSB dissapears

Hello all.
I’m new to the Arduino but have been working with the PIC and PicBasicPro for a while. So a bit of a learning curve with this.

I have my code working but there’s something odd that happens. Code described below:

PortC setup for Input. Switching to 0v and sending Port/s through Xbee Pro 900HP to multiple recievers. All inputs look and read fine(Serial Monitor on RX side) until input A5(PortC). When switched, it’s as though the port becomes one less. Or everything shifts.
I tried this with PortD also(ignoring 0,1 for the USB) and same thing on D7.

As I said it works but this is a curiosity.
I’ve included the code for anyone who wants to have a look
Thank you.
Ian

IOSend_FINAL_2018.ino (2.22 KB)

You did not mention which Arduino you are running this code on. Direct port manipulation is NOT portable. So, we need to know which Arduino you are using.

It would be helpful to know which pins you think correspond to PORTC and PORTD. It appers that you are aware that the hardware serial instance, Serial, uses pins 0 and 1. It is not as clear that you are aware that AltSoftSerial uses pins 8 and 9.

    packet.append<float>(PINC);
    packet.append<float>(PIND);

WTF? PINC and PIND are NOT 4 byte floats. They are one byte bytes.

Thanks for the reply.

I'm using the Uno v3. And yes, I am aware of the pin 8,9 thing. Thus not using PortB for the switch detection.

I pulled the port info from here: https://www.arduino.cc/en/Reference/PortManipulation

As for the 4 byte thing, I know the ports are only one. This is from the code that I mentioned I am tweaking. The extra bytes are for future expansion.

The extra bytes are for future expansion.

Having the extra bytes is one thing. Misinterpreting the existing bytes is another.

I suggest that you put the values in the payload AS BYTES. And, of course, get them out the same way.

Fair enough. But I've never had this problem before. Every BYTE is recevided correctly. Until the MSB is triggered. Then the MSB is lost. I've done port read with many 18F Pics with no problem. Plus running interrupts in ASM.

Just seemed odd and was hoping to see if anyone else had this issue.