Other Parts Discussed in Thread: MSP430FR5739
Hi I'm having a problem when trying to divide the int16_t into two (MSB,LSB) uint8_t numbers for transmission. It seems to occur for small negative numbers, -3, -2, -1 but recently it seems maybe only for -1. Code:
volatile int16_t countProcess = 0;
volatile uint8_t txByte = 0;
volatile uint8_t escByte = 0;
// When countProcess == 0xFF, (countProcess & 0xFF00) == 0xFF00 evaluates to 0 not 1 as (I) expected
void sendCounts(void)
{
// Start byte
while((UCA1IFG & UCTXIFG) == 0); // Wait for TX buffer to clear
UCA1TXBUF = 0xFF; // Start Btye
// MSB countProcess
if ((countProcess & 0xFF00) == 0xFF00){
txByte = 0;
escByte |= BIT2; // Set MSB overflow bit
}
else
txByte = ((countProcess & 0xFF00)>>8); // Load MSB of net count
while((UCA1IFG & UCTXIFG) == 0); // Wait for TX buffer to clear
UCA1TXBUF = txByte; // Send MSbyte of net count
// LSB countProcess
txByte = (countProcess & 0xFF); // Load LSB of net count
...
}
//A different technique: when countProcess == 255, txByte = (countProcess >> 8) yields txByte = 0 not 255 as (I) expected
void sendCounts(void)
{
// Start byte
while((UCA1IFG & UCTXIFG) == 0); // Wait for TX buffer to clear
UCA1TXBUF = 0xFF; // Start Btye
// MSB countProcess
txByte = (countProcess >> 8); // Load MSB of net count
if (txByte == 255){
//txByte =0;
escByte |= BIT2; // Set MSB overflow bit
}
while((UCA1IFG & UCTXIFG) == 0); // Wait for TX buffer to clear
UCA1TXBUF = txByte; // Send MSbyte of net count
// LSB countProcess
txByte = (countProcess & 0xFF); // Load LSB of net count
...
}
I'm hoping someone knows more about how signed to unsigned conversions are handled and maybe can point out what I'm missing. The chip is a MSP430FR5739.
Thanks,
Martin