I have the raspberry pi 3 model B and would like to communicate over i2c. I have heard that the bcm2835 and bcm2837 chip ar almost identical, so I should be able to use the bcm2835 library to communicate over i2c, yet I don't see anything happening.
- I have 2 pull ups from 10k
- this code shows me that I always get a NACK
a logic analyzer that shows me that the serial lines are always high and never go low
yes I did enable i2c in raspberry pi configurations > interfaces > i2c
Could anybody explain me what I am doing wrong?
EDIT:
- i2cdetect -y 1
pi@raspberrypi:~ $ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
pi@raspberrypi:~ $
This is the code I use to communicate, reason is always equal to 1 (=NACK):
#include <bcm2835.h> #include <stdio.h> #define slaveAddress 0x68 int main(int argc, char **argv) { char commands[1]; uint8_t reason; bcm2835_init(); bcm2835_i2c_begin(); printf("i2c busy\n"); bcm2835_i2c_setSlaveAddress(slaveAddress); bcm2835_i2c_set_baudrate(1000); bcm2835_delay(500); commands[0] = 0x35; reason = bcm2835_i2c_write(commands, 1); printf("reason: %d\n", reason); return 0; }
In the BCM2835 header file, I modified the base address from 0x20000000 to 0x3F00000000 (neither of them worked).
- this is my setup
- I tried to communicate with the module using the wiringPi library. That worked. So the issue has to do with my code somehow....
i2cdetect -y 1
, and include an SSCCE (not a link). – goldilocks♦ Apr 12 '17 at 13:02