Page 1 of 1

Getting initializer element is not constant when trying to init I2C

Posted: Sun Feb 05, 2017 5:10 pm
by Dohny
Hello guys,

I'm having problems using shared I2C module for two 1 bit ports on X216. When I try to define structure containing I2C ports like this:

Code: Select all

#include "es9038q2m.h"


#define DAC_REGWRITE(reg, val) {data[0] = val; i2c_shared_master_write_reg(i2c_dac, ES9028M_I2C_ADDR, reg, data, 1);}
#define DAC_REGWRITE_MONO(reg, val) {data[0] = val; i2c_shared_master_write_reg(i2c_dac, ES9028M_I2C_ADDR_MONO, reg, data, 1);}
#define DAC_REGREAD(reg, val)  {i2c_shared_master_read_reg(i2c_dac, ES9028M_I2C_ADDR, reg, val, 1);}

#define EEPROM_ADDRWRITE(addr, val) {data[0] = val; i2c_shared_master_write_reg(i2c_dac, E24AA02_ADDR, addr, data, 1);}
#define EEPROM_ADDRREAD(addr, val)  {i2c_shared_master_read_reg(i2c_dac, E24AA02_ADDR, addr, val, 1);}

on tile [0] : port p_scl = PORT_I2C_SCK;
on tile [0] : port p_sda = PORT_I2C_SDA;
struct r_i2c i2c_dac = {p_sda, p_scl};
on tile [0] : out port p_dac = PORT_T0_CONTROL;

void DAC_init(void)
{
    unsigned char data[1] = {0};
    i2c_shared_master_init(i2c_dac);
    ...
    
I'm getting initializer element is not constant error on the struct r_i2c... line.

Any idea where I'm making a mistake?

Thank you.

Re: Getting initializer element is not constant when trying to init I2C

Posted: Sun Feb 05, 2017 5:48 pm
by mon2
Believe you are missing the clock value and also the order of I2C ports declaration is incorrect.

Try:

Code: Select all

struct r_i2c i2c_dac = {p_scl, p_sda, 1000};
Reference:

Code: Select all

/** Struct that holds the data for instantiating the I2C module - it just
 * comprises two ports (the clock port and the data port), and the speed of
 * the bus which is a compile time define.
 */
typedef struct r_i2c {
    port scl;      /**< Port on which clock wire is attached. Must be on bit 0 */
    port sda;      /**< Port on which data wire is attached. Must be on bit 0 */
    unsigned int clockTicks; /**< Number of reference clocks per I2C clock,
                              *   set to 1000 for 100 Khz. */
} r_i2c;
from:

https://github.com/xcore/sc_i2c/blob/ma ... /src/i2c.h

Re: Getting initializer element is not constant when trying to init I2C

Posted: Sun Feb 05, 2017 6:07 pm
by Dohny
I tried that, now I belive the problem is that I still have lib_i2c in the workspace, when I delete the folder IDE imports it...even tho I dont have it in makefile, how is that possible? Any idea how to get rid of it?

edit:
Now I got it sorted. All the problems were caused by lib_i2c which I had included in another modul dependencies. I also had module i2c_simple and they obviously werent happy being in the same workspace.