Hi,
I'm trying to connect my axoloti to an Arduino Uno. I'm using the chibios i2c library for it and I'm embedding the code into a script2 object (btw. is it possible to do this in a *.axo object without having to care about threading?).
Problem is, my axoloti stops as soon as I fire the first i2c commands to the Arduino (and when they are received, without a connection everything goes fine).
This is the error I get, afterwards I have to unplug the USB cable in order to be able to reconnect again:
Done uploading patch
Start starting patch
Done starting patch
Start locking
Done locking
Ping: WaitSync Timeout, disconnecting now
Disconnect request
Control transfer failed: -7
The script I'm using looks like this (I don't have anything else, except disp/i objects in my patcher).
#include <hal.h>
struct data_pkg_t {
uint8_t channel;
uint8_t value;
};
void setup() {
palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(4)|PAL_STM32_PUDR_PULLUP|PAL_STM32_OTYPE_OPENDRAIN);// SCL
palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(4)|PAL_STM32_PUDR_PULLUP|PAL_STM32_OTYPE_OPENDRAIN);// SDA
static const I2CConfig i2cfg = {
OPMODE_I2C,
100000,
STD_DUTY_CYCLE,
};
i2cStart(&I2CD1, &i2cfg);
out2 = _INT(10);
}
void loop() {
chThdSleepSeconds(1);
struct data_pkg_t channelValue;
msg_t msg = i2cMasterReceive(&I2CD1, 8,(uint8_t *) &channelValue, sizeof(channelValue));
if (msg != RDY_OK) {
out2 = _INT(i2cGetErrors(&I2CD1));
return;
}
out1 = _INT(channelValue.channel);
out2 = _INT(channelValue.value);
}
I already tried wrapping my call i2cAcquireBus() and i2cReleaseBus() with no luck. The problem even occurs when in the following cases:
- Using i2cMasterReceiveTimeout
- Not calling any i2cMasterReceive method, but just acquire and release
- Using simple types instead of the struct
The arduino code is basically https://www.arduino.cc/en/Tutorial/MasterReader (Code for Slave Sender - Program for Arduino 2)
Any hints? I don't really know how to debug this further, the next step will be starting gdb... I could switch to UART, but I would really want to know, what the problem is here.