cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Configuartion

B_D_R
Associate II

Hi Friend,

I am trying to configure I2C on the STM32MP157 evaluation board to use I2C5 in master transmitter mode. However, I'm having trouble sending the address because the start bit is not being set. Could someone please help me?

Also which register has to check slave address ackno.??

 

GPIO , Pin, I2C configuartion code :

//----------------------I2C5----------------------

/*---------------------PIN CONFIGURATION-----------------*/

 

// 1. Enable the I2C CLOCK and GPIO CLOCK --I2C5 ---PA---- SDA-12, SCL -11

RCC->MC_AHB4ENSETR |= (1<<0); //Enable clock of portA

RCC->MC_APB1ENSETR |= (1<<24); //Enable clock for i2c 5

 

 

// 2. Configure the I2C PINs for ALternate Functions

// a) Select Alternate Function in MODER Register

 

GPIOA->MODER |= (1<<23); //PA11-----10

GPIOA->MODER &= ~(1<<22);

 

GPIOA->MODER |= (1<<25); //PA12-----10

GPIOA->MODER &= ~(1<<24);

 

 

// b) Select Open Drain Output

GPIOA->OTYPER |= (1<<11);

GPIOA->OTYPER |= (1<<12);

 

 

// C) select VERY High SPEED for the PINs

GPIOA->OSPEEDR |= (1<<23); //PA11-----11

GPIOA->OSPEEDR |= (1<<22);

 

GPIOA->OSPEEDR |= (1<<25); //PA12-----1

GPIOA->OSPEEDR |= (1<<24);

 

 

// D)Select Pull-up for both the Pins

GPIOA->PUPDR |= (1<<22); //PA11-----01

GPIOA->PUPDR &= ~(1<<23);

 

GPIOA->PUPDR |= (1<<24); //PA12-----01

GPIOA->PUPDR &= ~(1<<25);

 

 

// e) Configure the Alternate Function in AFR Register

 

GPIOA->AFR[1] = 0x00; //HIGH SIDE ALL PIN SET TO 0

GPIOA->AFR[1] |= (1<<14); // 0100 - ARFH11

GPIOA->AFR[1] |= (1<<18); //0100 - ARFH12

 

 

/*-----------------I2C Setting CONFIGURATION----------------------*/

// 3. Reset the I2C

//I2C Control Register 1 (I2C_CR1) - use to set and reset i2c

//A software reset can be performed by clearing the PE bit in the I2C_CR1 register.

I2C5->CR1 &= ~(1<<0); //PE - AT 0BIT USE TO SOFT. SET RESET 0FOR RESET

I2C5->CR1 |= (1<<0);

I2C5->CR1 &= ~(1<<0);

 

// 4. Program the peripheral input clock in I2C_CR2 Register in order to generate correct timings (I2C timing register)

 

I2C5->TIMINGR |= (30<<0);

I2C5->TIMINGR |= (21<<8);

I2C5->TIMINGR |= (1<<20);

I2C5->TIMINGR |= (12<<28);

 

// I2C control register 2 ---- Automatic end mode (master mode) to 1

I2C5->CR2 |= (1<<25);

 

// Enable I2C -- at PE CR1

 

 

 

 

 

 

 

 

 

Function to send slave address code:

 

 

void Matser_send_slave_Add_transmit(void)

{

 

I2C5->CR2 &= ~(1<<11); //register 11 - ADD10 ---- select salve address 7bit/ 10 bit

 

I2C5->CR2 |= (2<<0); //Slave address enter at SADD /* here slave address as 2 */

 

I2C5->CR2 &= ~(1<<10); //RD_WRN---- Register use to select master - transmit or receive mode

 

I2C5->CR2 |= (11<<16);

//AFTER ALL THE CHANGES START BIT IS TO BE SET

I2C5->CR2 |= (1<<13); //Start Bit

 

while(!((I2C5->CR2)&(1<<15)));

 

}

 

 

 

 

Regards.

I2C5->CR1 |= (1<<0);

 

2 REPLIES 2
B_D_R
Associate II

// Enable I2C -- at PE CR1

I2C5->CR1 |= (1<<0);

 

Andrew Neil
Evangelist III