getc() compiler error: Expression must be a modifiable lvalue (E137)

05 Mar 2011

SOLVED: I'm retarded, forgot the extra = in the if statement. Left posted code uncorrected.

I'm trying to write a mbed serial interface to read data output from CH robotics new UM6 AHRS/IMU. http://www.chrobotics.com/docs/UM6_datasheet.pdf

So far I've gotten thru recognizing the "snp" (start new packet) string with the mbed.

The next packet/byte sent by the UM6 is called the PT byte. This byte contains a bunch of information which depends on which bits are set, but this byte is always the same value for the default UM6 setup.

The byte is 0xC8, but when I try to use getc() in any way with this byte the program either freezes or gives me the compile error: Expression must be a modifiable lvalue (E137)

I know its probably some property of getc() that I don't know about.

Could anyone help out and tell me why getc() won't work, and what alternative I can use.

I knew I get stuck on the bitshifting part because the UM6 transmits 16 bit signed int as two 8 bit int, but I didn't think I would get stuck on something this simple.

Here's my work so far, with the resulting error already stated at the 0xC8 if statement.

#include "mbed.h"              

Serial pc(USBTX, USBRX);
Serial uart(p28, p27);

DigitalOut pc_activity(LED1);
DigitalOut uart_activity(LED2);

int state = 0;
    
int main() {
    // set serial uart baud 115200
    uart.baud(115200);
    
    // set pc baud 115200
    pc.baud(115200);
    
   
    int packet_state = 0;  // STATE OF PACKET, ZERO = WAIT FOR 'snp'
     
    while(packet_state == 0) {
         //  pc.putc(uart.getc()); // Serial pass thru
     
      
      // READ 'snp' (START NEW PACKET) FROM UM6 AHRS
      
           if (uart.getc() == 0x73 ) {  
            // pc.putc(0x73);
             pc.putc('s');
             state = 1; 
          }
           
           if (uart.getc() == 0x6E ) {  
             // pc.putc(0x6E);
              pc.putc('n');
             state ++; 
             // uart_activity = !uart_activity;
          }
          
          
           if (uart.getc() == 0x70 ) {  
            // pc.putc(0x70);
             pc.putc('p');
             state ++; 
            //  uart_activity = !uart_activity;
          }
          
          
          // PT (packet type)
          if (uart.getc() = 0xC8 ) {
          state = 0;
          pc.putc('P');
          pc.putc('T');
          state ++;
          }
         
    }
}
05 Mar 2011

if (uart.getc() = 0xC8 ) {

Finger problems. You are missing an =, that should be ==

(btw, I must be retarded too, I missed the SOLVED right at the front ;)