scott.mccain
Member
I've searched the forums for this specific problem and while I've found a few examples that are close, nothing that matches what I'm looking for specifically. I do apologize though in advance if my search was incomplete.
Here is my issue:
I have a Teensy3.2 hooked up to an Atmega328. I created a sketch and used AtmelStudio to create a project from the Arduio Sketch which I then flashed to the chip. This is essentially the same as the code that would run on the chip if uploaded via Arduino, but it bypasses the bootloader so the code executes immediately. That code is shown below (some omissions for brevity):
Here is my Teensy code (uploaded using Arduino IDE):
You'll notice the commented delays between calls to setColor. If I don't specify those delays the transmissions end up getting "dropped". That's the best way I can explain it. I put some serial debugging statements and when I don't have the delay I basically get every other transmission as demonstrated by printing out the raw bytes as they are received. When I add the delay back I see every transmission in the correct order.
Even without the serial debugging statements if I have the output go to leds or some other indicator I see every other packet take effect just as I see every other packet in the serial debugger. I've added pull up resistors and I tried running the Teensy at 24Mhz to slow the clock down, but still no luck.
I've attached images to the post.
Thank you in advance for any assistance.
Here is my issue:
I have a Teensy3.2 hooked up to an Atmega328. I created a sketch and used AtmelStudio to create a project from the Arduio Sketch which I then flashed to the chip. This is essentially the same as the code that would run on the chip if uploaded via Arduino, but it bypasses the bootloader so the code executes immediately. That code is shown below (some omissions for brevity):
Code:
/*Begining of Auto generated code by Atmel studio */
#include <Arduino.h>
/*End of auto generated code by Atmel studio */
#include <Wire.h>
//Beginning of Auto generated function prototypes by Atmel Studio
void receiveWireData(int howMany);
//End of Auto generated function prototypes by Atmel Studio
void setup() {
Wire.begin(0x10);
Wire.onReceive(receiveWireData);
}
void loop() {
// process any queued packets from recieveWireData
}
void receiveWireData(int howMany) {
// should be 7 bytes total - first byte is offset, followed by three 16 bit integers in big endian (network byte order)
// first byte is always the address
uint8_t address = (uint8_t)Wire.read();
while(Wire.available()) {
// read rest of transmission
byte ch = (byte)Wire.read();
}
// queue packet to be processed
}
Here is my Teensy code (uploaded using Arduino IDE):
Code:
#include <Wire.h>
void setup() {
// put your setup code here, to run once:
Wire.begin();
}
void loop() {
// put your main code here, to run repeatedly:
setColor(0, 0xff0, 0x00, 0x00);
//delay(20);
setColor(1, 0xff0, 0x00, 0x00);
//delay(20);
setColor(2, 0xff0, 0x00, 0x00);
//delay(20);
setColor(3, 0xff0, 0x00, 0x00);
delay(500);
setColor(0, 0xf00, 0xf00, 0x00);
//delay(20);
setColor(1, 0xf00, 0xf00, 0x00);
//delay(20);
setColor(2, 0xf00, 0xf00, 0x00);
//delay(20);
setColor(3, 0xf00, 0xf00, 0x00);
delay(500);
}
void setColor(uint8_t channel, uint16_t red, uint16_t green, uint16_t blue) {
Wire.beginTransmission(0x10); // transmit to device #0x10
Wire.write(channel);
Wire.write((byte)(red>>8));
Wire.write((byte)(red&0xff));
Wire.write((byte)(green>>8));
Wire.write((byte)(green&0xff));
Wire.write((byte)(blue>>8));
Wire.write((byte)(blue&0xff));
Wire.endTransmission(); // stop transmitting
}
You'll notice the commented delays between calls to setColor. If I don't specify those delays the transmissions end up getting "dropped". That's the best way I can explain it. I put some serial debugging statements and when I don't have the delay I basically get every other transmission as demonstrated by printing out the raw bytes as they are received. When I add the delay back I see every transmission in the correct order.
Even without the serial debugging statements if I have the output go to leds or some other indicator I see every other packet take effect just as I see every other packet in the serial debugger. I've added pull up resistors and I tried running the Teensy at 24Mhz to slow the clock down, but still no luck.
I've attached images to the post.
Thank you in advance for any assistance.
Last edited: