cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F429 Discovery- I2C communication with Arduino Mega ADK

Daattavya Aggarwal
Associate II
Posted on August 24, 2017 at 23:40

Hello. I am trying to perform I2C communication between the stm32f429 disco board and an arduino mega adk. When I used my debugger I found that my code gets stuck in the while loop inside the send_data function infinitely. Although my led on pg13 is lighting up, I feel that the arduino isn't actually sending an acknowledge. Any help would be greatly appreciated.

void led_init1()

{

RCC ->AHB1ENR |= RCC_AHB1ENR_GPIOGEN;

GPIOG ->MODER |= GPIO_MODER_MODER13_0;

GPIOG ->OTYPER &= ~(GPIO_OTYPER_OT_13);

GPIOG ->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR13_0;

GPIOG ->PUPDR &= ~(GPIO_PUPDR_PUPDR13);

}

void scl_pin()

{

RCC ->AHB1ENR |= RCC_AHB1ENR_GPIOBEN;

GPIOB ->MODER |= GPIO_MODER_MODER6_1;

GPIOB ->AFR[0] = GPIO_AF4_I2C1<<24;

}

void sda_pin()

{

RCC ->AHB1ENR |= RCC_AHB1ENR_GPIOBEN;

GPIOB ->MODER |= GPIO_MODER_MODER7_1;

GPIOB ->OTYPER &= ~(GPIO_OTYPER_OT_7);

GPIOB ->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR7_1;

GPIOB ->PUPDR |= GPIO_PUPDR_PUPDR7_0;

GPIOB ->AFR[0] = GPIO_AF4_I2C1<<28;

}

void i2c_setup()

{

RCC->APB1ENR |= RCC_APB1ENR_I2C1EN;

I2C1 ->CR2 |= I2C_CR2_FREQ_3;

I2C1 ->CCR |= 0x28;

I2C1 ->TRISE = 0x09;

I2C1 ->CR1 |= I2C_CR1_PE;

I2C1 ->CR1 |= I2C_CR1_ACK;

I2C1 ->CR1 |= I2C_CR1_START;

I2C1 ->DR = 0x08;

}

void send_data(uint8_t data)

{

while(!(I2C1->SR1 & I2C_SR1_TXE)){}

I2C1 ->DR = data;

}

int main(void)

{

led_init1();

scl_pin();

sda_pin();

i2c_setup();

if(I2C1->CR1 & I2C_CR1_ACK)

GPIOG ->BSRRL |= GPIO_BSRR_BS_13;

while(1)

{

send_data(5);

}

}

#i2c #stm32
1 REPLY 1
Posted on August 25, 2017 at 02:56

The number of people wanting to wade through this kind of code is fairly small.

Put a scope on the pins, and inspect the waveforms.

Make sure you have the pins configured in OD (Open Drain) mode, with internal or external pull-ups.

Make sure the boards share a common ground.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..