I'm trying to get the Atmega328 to communicate with a DAC...
So right now im just trying to get the I2C bus to do something (no DAC connected).
Both SDA and SCL just stay idle at Vcc. I have tried it using the 16MHz external crystal and 8MHz internal crystal. I have used I2C before with the newer arduino w/ the SMT MCUs with no problems.
I have both SDA and SCL tied to 10k pull up resistors. ( It behaves the same with and without the resistors)
Heres the code:
#include <Wire.h>
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600);
}
byte x = 0;
void loop() {
Wire.beginTransmission(13); // transmit to device #13
Wire.write('a'); // fist byte
Wire.write('a'); // second byte
Wire.endTransmission(); // stop transmitting
analogWrite(9,125); // LED ON
delay(500);
analogWrite(9,0); // LED OFF
delay(500);
}
The LED blinks on/off proving that the I2C commands are being executed, except nothing is happening.
Also, I do not remember which Programmer option I am supposed to use or if it makes a difference.
Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. Using code tags and other important information is explained in the How to use this forum post.
tonyd5:
Is the Wire library only set up for Arduino-Arduino communication
No, unless things have changed in the library after IDE1.6.6 (the version I'm using).
Note: the below does not explain the behaviour that you observe with the scope.
tonyd5:
w/ the slave pulling one of the pins low or something crazy like that?
The slave is supposed to generate an ACK condition after receiving a byte. No slave and that will not happen
You can (and should) check the result of the endTransmission(); if nothing is connected you will get a NACK (2) back from endTransmission() when the device address is send over the wire.
endTransmission() calls twi_write() and returns the value that twi_write() returns
From twi.c
* Output 0 .. success
* 1 .. length to long for buffer
* 2 .. address send, NACK received
* 3 .. data send, NACK received
* 4 .. other twi error (lost bus arbitration, bus error, ..)
Note:
endTransmission() does not stop the transmitting; it actually starts the data transfer.
Sorry about the code tags. First post on this and I could not find them...
Anyway I tried the Scanner program and got the same problem.
Could not find the device (Though DAC could be fried at this point because I have been messing with it so much).
Regardless, when I looked at SCL and SDA on the scope with no device connected they both just sit at Vcc. Same problem as before. ( 10k pullup resistors)
I just want to get this thing to transmit data. They only time I have successfully seen waveforms is when the bus is connected to another arduino.
I have it tried it w/ 3 chips and got the same result so this is not it.
Still does not explain why nothing is transmitted when there is no device on the bus. Maybe the MCU has some way of checking if there is no load and just doesn't send anything after that.
mistergreen:
No device, no ground & vcc -> no transmission ?
There should still be activity on the bus. The wire / twi library does not care. It will send data, it will not get an ACK and only then decide that there is no device.
It has to be open-drain / open-transistor. In a multimaster capable system, push-pull can not be used because multiple masters can apply different levels on the SCL and SDA line at the same time; you would blow up your masters while one is transmitting a logic 1 and another one is transmitting a logic low.