1

I'm porting some Arduino code to a mcu in pure c.

The data type byte is used in the arduino code which is not supported by the compiler. I'm wondering which data byte should I use uint8_t or unsigned char? Which is more correct? I'm relatively new to coding.

I gather it depends what the intent of the variable.

The variable will store hex data from this camera (screen shot of output).

sample output

byte incomingbyte;
void loop()
{
    byte a[32];
    int ii;
    while(Serial2.available()>0)
    {
        incomingbyte=Serial2.read();
    } 
}

Many thanks

ultrasonic bananna
  • 193
  • 1
  • 3
  • 12
  • You need to be clear what you mean by "hex data". Do you mean you're expecting two hex digits (8 bits of data) in each byte read, or do you mean you're expecting one hex digit (4 bits of data) in each character read? In the former case, you could say the variable will store raw bytes (or raw, 8-bit bytes) from the camera. – Ian Abbott Jan 18 '16 at 16:53
  • If `byte` is not supported by the compiler, you can either do this `#define byte uint8_t` or you can do this `typedef uint8_t byte;` but either one must be visible to the code modules where `byte` is used. – Weather Vane Jan 18 '16 at 17:01
  • Thanks @Ian Abbott I'm expecting two hex digits. – ultrasonic bananna Jan 20 '16 at 16:11

1 Answers1

0

According to this link an arduino byte is an unsigned 8 bit value. I personally would use the more expressive uint8_t, but an unsigned char would work as well.

What type is used on the new platform to return a byte received from the serial port?

Might also want to check out this question.

Community
  • 1
  • 1
Chimera
  • 5,884
  • 7
  • 49
  • 81