cancel
Showing results for 
Search instead for 
Did you mean: 

x-nucleo-6180XA1

antonioB
Associate II
Posted on May 04, 2016 at 16:07

Hi to all, i have this shield x-nucleo-6180XA1 with mi STM32L152RE, i setting PB8 and PB9 for I2C1, i want to test the shild i want to see the who i am,  i write this easy code 

 &sharpdefine IDENTIFICATION__MODEL_ID  0x000   //who I am

&sharpdefine PROXW  0x52

&sharpdefine PROXR  0x53

&sharpdefine DEFUALT_ADDR 0X29

void I2C_WHOAMI(I2C_HandleTypeDef *hi2c1, __IO uint8_t whoami){

     

  while((hi2c1->Instance->SR2&BUSY)==BUSY);

  //  Start

    hi2c1->Instance->CR1 |= START;

  while((hi2c1->Instance->SR1&SB)!=SB);

  dummy16 = hi2c1->Instance->SR1;

 

  hi2c1->Instance->DR = PROXW;

  while((hi2c1->Instance->SR1&ADDR)!=ADDR);

  dummy16 = hi2c1->Instance->SR1;

  dummy16 = hi2c1->Instance->SR2;

  while((hi2c1->Instance->SR1&TXE)!=TXE);

 

 hi2c1->Instance->DR = whoami; //WHOAMI;

  while((hi2c1->Instance->SR1&(TXE|BTF))!=(TXE|BTF));

  //  Restart

  hi2c1->Instance->CR1 |= START;

  while((hi2c1->Instance->SR1&SB)!=SB);

  dummy16 = hi2c1->Instance->SR1;

  hi2c1->Instance->DR = PROXR;

  while((hi2c1->Instance->SR1&ADDR)!=ADDR);

  dummy16 = hi2c1->Instance->SR1;

  dummy16 = hi2c1->Instance->SR2;

  while((hi2c1->Instance->SR1&(RXNE))!=(RXNE));

  dummy16 = hi2c1->Instance->DR;

  if (dummy16==(uint16_t)180)    //0xB4

  {

    HAL_GPIO_WritePin(LD2_GPIO_Port,LD2_Pin,GPIO_PIN_SET);

 while((1));

  }

hi2c1->Instance->CR1 |= STOP;

}

in the main.c  i have this

  // whoami

I2C_WHOAMI(&hi2c1,IDENTIFICATION__MODEL_ID);

i don't see nothing, i use this code with other shield it's work well.

can you help me?

best regards

A.

#nucleo #x-nucleo #i2c
2 REPLIES 2
antonioB
Associate II
Posted on May 04, 2016 at 16:55

// I2C REGISTER

//  I2C->CR1

#define ACK             (uint16_t)0x400

#define STOP            (uint16_t)0x200  //OPPURE 1<<9

#define START           (uint16_t)0x100 //OPPURE 1<<8

#define I2CBUS          (uint16_t)0x0

#define PEREN           (uint16_t)0x1

// I2C->SR1

#define SB              (uint16_t)0x1

#define ADDR            (uint16_t)0x2

#define BTF             (uint16_t)0x4

#define RXNE            (uint16_t)0x40

#define TXE             (uint16_t)0x80

//  I2C->SR2

#define BUSY            (uint16_t)0x2

antonioB
Associate II
Posted on July 11, 2016 at 13:52

Hi to all, i fix it, i have a problem with cubemx and the able the i2c1

best regards

A.