Reply
Highlighted
Posts: 22
Registered: ‎07-03-2017
Accepted Solution

EFM32 I2C setup and detection slave device(how to send data properly)

Hi,

I want to detect my sensor with bus I2C, but I met a problem to setup. Here is my process:

 

I use BGM121 blueGecko board.

 

1. I use simplicity studio editor to setup PC11 and PC10 en mode "Wired-and pullup filter". Enable I2C and make PC11 with data, PC10 with SCL.

 

2. in the code I did

 

void init_I2c(void){
   I2CSPM_Init_TypeDef init = 	                                              \
  { I2C0,                      /* Use I2C instance 0 */                       \
    gpioPortC,                 /* SCL port */                                 \
    10,                        /* SCL pin */                                  \
    gpioPortC,                 /* SDA port */                                 \
    11,                        /* SDA pin */                                  \
    14,                        /* Location of SCL */                          \
    16,                        /* Location of SDA */                          \
    0,                         /* Use currently configured reference clock */ \
	92000,    				  /* Set to standard rate  */                     \
    i2cClockHLRStandard,       /* Set to use 4:4 low/high duty cycle */       \
  };
	I2CSPM_Init(&init);
}


bool counter_Detect(I2C_TypeDef *i2c, uint8_t addr)
{
  I2C_TransferSeq_TypeDef    seq;
  I2C_TransferReturn_TypeDef I2C_Status;
  uint8_t                    i2c_write_data[1];

  seq.addr  = addr;
  seq.flags = I2C_FLAG_WRITE;
  i2c_write_data[0] = addr;
  seq.buf[0].data   = (uint8_t *)i2c_write_data;
  seq.buf[0].len    = sizeof(addr);
  seq.buf[1].len    = 0;
  I2C_Status = I2C_TransferInit(I2C0, &seq);


   while (I2C_Status == i2cTransferInProgress)
   {
	   I2C_Status = I2C_Transfer(I2C0);
  }
  if (I2C_Status != i2cTransferDone) {
	printf("non detecter, we have return value :%d\n\r",I2C_Status);
    return false;
  }
  printf("detect!\n\r");

  return true;
}

3. in the main function:

 

  enter_DefaultMode_from_RESET();

  init_I2c(); 

  counter_Detect(I2C0,  1<<0x20);

 

4. I connect pins with pins on my sensors

I get return value sometimes -2 and -1(NACK). 

in the scope, I got nothing except 2v in DATA and SCL(due to pull up resistor?).

Posts: 22
Registered: ‎07-03-2017

Re: EFM32 I2C setup and detection slave device(how to send data properly)

It works better, I can see the clock and data(I should config my scope en pente descend mode). otherwise, the configuration is correct. now I should find why I haven't got ACK but NACK. 

 

 

Posts: 2,375
Registered: ‎10-14-2014

Re: EFM32 I2C setup and detection slave device(how to send data properly)

I am not sure I understand this line of code correctly or not. do you mean the I2C slave address is 1<<32?

 

counter_Detect(I2C0,  1<<0x20);

WeiguoLu
Posts: 22
Registered: ‎07-03-2017

Re: EFM32 I2C setup and detection slave device(how to send data properly)

Hi,

My case is very particuliar, All depends on my sensor side. so, It's normal to have some problem.

 

Thanks,

Posts: 3,144
Registered: ‎02-07-2002

Re: EFM32 I2C setup and detection slave device(how to send data properly)

1<<0x20 or 1<<32 equals 0 on a 32 bit platform like the EFM32.