Hello everyone,
I'm a newbie trying to port over code for my Atmega328P to a Teensy LC.
I have the following code running fine on my Atmega328P. Pretty much what it does is creates a Struct Variable and prints the variable's raw values to serial (To console for now, but later to another device via Serial1).
Everything compiles fine on both Atmega328P and Teensy LC. However, the serial output is different.
On Atmega328P I get what I expect:
On the Teensy LC i get:
The reason for this code is that the library that I'm using expects me to pass the Struct variable's values as a uint8_t pointer or array to another function so it can be sent via Serial to another connected device. But as you can see, I get different results depending on the platform.
Thanks in advance!
I'm a newbie trying to port over code for my Atmega328P to a Teensy LC.
I have the following code running fine on my Atmega328P. Pretty much what it does is creates a Struct Variable and prints the variable's raw values to serial (To console for now, but later to another device via Serial1).
Code:
typedef struct zdo_simple_desc_resp_header_t {
uint8_t status;
uint16_t network_addr_le;
uint8_t length;
} zdo_simple_desc_resp_header_t;
typedef struct zdo_simple_desc_header_t {
uint8_t endpoint;
uint16_t profile_id_le;
uint16_t device_id_le;
uint8_t device_version;
} zdo_simple_desc_header_t;
void setup() {
Serial.begin(9600);
while(!Serial);
Serial.println("Started!");
struct {
uint8_t transaction;
struct zdo_simple_desc_resp_header_t header;
struct zdo_simple_desc_header_t descriptor;
uint8_t clusters[4];
} rsp;
rsp.transaction = 0x01;
rsp.header.status = 0x02;
rsp.header.network_addr_le = 0x0403;
rsp.header.length = 0x05;
rsp.descriptor.endpoint = 0x06;
rsp.descriptor.profile_id_le = 0x0807;
rsp.descriptor.device_id_le = 0x0a09;
rsp.descriptor.device_version = 0x0b;
rsp.clusters[0] = 0x0c;
rsp.clusters[1] = 0x0d;
rsp.clusters[2] = 0x0e;
rsp.clusters[3] = 0x0f;
uint8_t* resp = &(rsp.transaction);
for (uint8_t i = 0; i < 15; i++)
{
Serial.println(resp[i], HEX);
}
}
void loop() {
// put your main code here, to run repeatedly:
}
Everything compiles fine on both Atmega328P and Teensy LC. However, the serial output is different.
On Atmega328P I get what I expect:
Code:
Started!
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
On the Teensy LC i get:
Code:
Started!
1
0
2
61
3
4
5
0
6
0
7
8
9
A
B
The reason for this code is that the library that I'm using expects me to pass the Struct variable's values as a uint8_t pointer or array to another function so it can be sent via Serial to another connected device. But as you can see, I get different results depending on the platform.
Thanks in advance!