Is it possible to connect directly the SCL and SDA lines of two stm32f411re? One will be the master and one will be the slave? Here is the code for the master. Is it correct?  How  to set up the slave?  the master will send a data and the slave will receive it. Is acknowledeg bit necessary? feel free to modify the code below for any changes needed. for the master: #include <stdint.h>  #include <stm32f4xx.h> #include "i2c.h"     void I2C_Config (void){   RCC->APB1ENR |= (1<<21); RCC->AHB1ENR |= (1<<1);   GPIOB -> MODER |= (2<<16) | (2<<18); GPIOB -> OTYPER |= (1<<8) | (1<<9); GPIOB -> OSPEEDR |= (3<<16) | (3<<18); GPIOB -> PUPDR |= (1<<16) | (1<<18); GPIOB -> AFR[1] |= (4<<0) | (4<<4);   I2C1 ->CR1 |= (1<<15); I2C1 ->CR1 &=~ (1<<15);   I2C1 ->CR2 |= (45<<0);   I2C1 ->CCR = 225<<0;   I2C1->TRISE = 46;   I2C1->CR1 |= (1<<1); }   void I2C_Start (void) {   I2C1 -> CR1 |= (1<<8); // GENERATE START while (!(I2C1->SR1 & (1<<0))); //WAIT FOR SB BIT TO SET   }   void I2C_Write (uint8_t data){   while (!(I2C1->SR1 & (1<<7))); // wait for TXE bit to set I2C1->DR = data; while (!(I2C1->SR1 & (1<<2))); //wait for BTF bit to set   }   void I2C_Address (uint8_t Address) { I2C1->DR = Address; //send the address while (!(I2c1->SR1 & (1<<1))); uint8_t temp = I2C1 ->SR1 | I2C1->SR2; //read SR1 and SR2 to clear the ADDR bit   }   void I2C_stop(void) { I2C1->CR1 |= (1<<9); }     int main(void) { // Initialize I2C I2C_Config();   // Start I2C communication I2C_Start();   // Address the slave (replace SLAVE_ADDRESS with the actual address of the slave) I2C_Address(SLAVE_ADDRESS); //edit later address of another stm32   // Write data to the slave uint8_t data_to_send = 0x01; // Example data to send I2C_Write(data_to_send);   // Stop I2C communication I2C_Stop();   while(1); // Loop indefinitely   return 0;   }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Is it possible to connect directly the SCL and SDA lines of two stm32f411re? One will be the master and one will be the slave? Here is the code for the master. Is it correct?  How  to set up the slave?  the master will send a data and the slave will receive it. Is acknowledeg bit necessary? feel free to modify the code below for any changes needed.

for the master:

#include <stdint.h> 

#include <stm32f4xx.h>

#include "i2c.h"

 

 

void I2C_Config (void){

 

RCC->APB1ENR |= (1<<21);

RCC->AHB1ENR |= (1<<1);

 

GPIOB -> MODER |= (2<<16) | (2<<18);

GPIOB -> OTYPER |= (1<<8) | (1<<9);

GPIOB -> OSPEEDR |= (3<<16) | (3<<18);

GPIOB -> PUPDR |= (1<<16) | (1<<18);

GPIOB -> AFR[1] |= (4<<0) | (4<<4);

 

I2C1 ->CR1 |= (1<<15);

I2C1 ->CR1 &=~ (1<<15);

 

I2C1 ->CR2 |= (45<<0);

 

I2C1 ->CCR = 225<<0;

 

I2C1->TRISE = 46;

 

I2C1->CR1 |= (1<<1);

}

 

void I2C_Start (void)

{

 

I2C1 -> CR1 |= (1<<8); // GENERATE START

while (!(I2C1->SR1 & (1<<0))); //WAIT FOR SB BIT TO SET

 

}

 

void I2C_Write (uint8_t data){

 

while (!(I2C1->SR1 & (1<<7))); // wait for TXE bit to set

I2C1->DR = data;

while (!(I2C1->SR1 & (1<<2))); //wait for BTF bit to set

 

}

 

void I2C_Address (uint8_t Address)

{

I2C1->DR = Address; //send the address

while (!(I2c1->SR1 & (1<<1)));

uint8_t temp = I2C1 ->SR1 | I2C1->SR2; //read SR1 and SR2 to clear the ADDR bit

 

}

 

void I2C_stop(void)

{

I2C1->CR1 |= (1<<9);

}

 

 

int main(void)

{

// Initialize I2C

I2C_Config();

 

// Start I2C communication

I2C_Start();

 

// Address the slave (replace SLAVE_ADDRESS with the actual address of the slave)

I2C_Address(SLAVE_ADDRESS); //edit later address of another stm32

 

// Write data to the slave

uint8_t data_to_send = 0x01; // Example data to send

I2C_Write(data_to_send);

 

// Stop I2C communication

I2C_Stop();

 

while(1); // Loop indefinitely

 

return 0;

 

}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY