Multiple i2c port drive & Multiple SPI port drive

Post here all questions related to LibMaple core if you can't find a relevant section!
madhavan
Posts: 29
Joined: Fri May 21, 2021 1:22 am

Multiple i2c port drive & Multiple SPI port drive

Post by madhavan »

hi ,

board : blue pill stm32f103c8t8 Arduino Preference :http://dan.drown.org/stm32duino/package ... index.json

Aim1(Project 1) : Have to connect to 2 i2c port ..... one is for I2c LCD Display (16x2) ..... second is for external eeprom ( 24lseries).

Currently i have connected First i2c port for LCD & second i2c port is eeprom i couldn't connect eeprom and i don't know how chose second i2c port . if i include the eeprom .h then compile error is coming like multiple header .

please suggest some example for above combination

-------------------------------------------------------------------------------------------------------------------------------------------------------

Aim2(project2) : Have to connect the 2 spi port ... first spi port is for TFT 3.5 inch lcd and second spi port is for Windfond Serail Flash memory - w25q32 .

Aim3 ( Project 3 ) : Have to connect 2 i2c port ....... one is for i2c for temperature sensor and second i2c port for a/d convertor .

please suggest some example for above combination
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: Multiple i2c port drive & Multiple SPI port drive

Post by stevestrong »

To use the second I2C port you can use following lines as shown in
https://github.com/rogerclarkmelbourne/ ... no#L29-L31 (remove comment from the beginning of the lines).

For SPI please look at this example:
https://github.com/rogerclarkmelbourne/ ... _ports.ino
You can open it with Arduino IDE by navigating the examples in the menu File -> Examples -> Examples for Generic STM32F103C series -> SPI -> using_spi_ports.
madhavan
Posts: 29
Joined: Fri May 21, 2021 1:22 am

Re: Multiple i2c port drive & Multiple SPI port drive

Post by madhavan »

i need to store the adc value into eeprom by mapping as 8 bit data and need read same value but reading showing as 0 nothing is stored .

Code: Select all

#include "Wire.h"

TwoWire WIRE2 (2,I2C_FAST_MODE);
#define Wire WIRE2
 

 
// EEPROM I2C Address
#define EEPROM_I2C_ADDRESS 0x51
 
// Analog pin for potentiometer
int analogPin = PA1;
 
// Integer to hold potentiometer value
int val = 0;
 
// Byte to hold data read from EEPROM
int readVal = 0;
 
// Integer to hold number of addresses to fill
int maxaddress = 1500;
 

 
 
// Function to write to EEPROOM
void writeEEPROM(int address, int val, int i2c_address)
{
  // Begin transmission to I2C EEPROM
  Wire.beginTransmission(i2c_address);
 
  // Send memory address as two 8-bit bytes
  Wire.write((int)(address >> 8));   // MSB
  Wire.write((int)(address & 0xFF)); // LSB
 
  // Send data to be stored
  Wire.write(val);
 
  // End the transmission
  Wire.endTransmission();
 
  // Add 5ms delay for EEPROM
  delay(5);
}
 
// Function to read from EEPROM
byte readEEPROM(int address, int i2c_address)
{
  // Define byte for received data
  byte rcvData = 0xFF;
 
  // Begin transmission to I2C EEPROM
  Wire.beginTransmission(i2c_address);
 
  // Send memory address as two 8-bit bytes
  Wire.write((int)(address >> 8));   // MSB
  Wire.write((int)(address & 0xFF)); // LSB
 
  // End the transmission
  Wire.endTransmission();
 
  // Request one byte of data at current memory address
  Wire.requestFrom(i2c_address, 1);
 
  // Read the data and assign to variable
  rcvData =  Wire.read();
 
  // Return the data as function output
  return rcvData;
}
 
 
void setup()
{
  // Connect to I2C bus as master
  Wire.begin();
 
  // Setup Serial Monitor
  Serial.begin(9600);
 
 
 
  // Print to Serial Monitor
  Serial.println("Start Recording...");
 
  // Run until maximum address is reached
 
  for (int address = 0; address <= maxaddress; address++) {
 
    // Read pot and map to range of 0-180 for servo
    val = map(analogRead(analogPin), 0, 4095, 0, 180);
 
    // Write to the servo
    // Delay to allow servo to settle in position
    
    delay(15);
 
    // Record the position in the external EEPROM
    writeEEPROM(address, val, EEPROM_I2C_ADDRESS);
 
    // Print to Serial Monitor
    Serial.print("ADDR = ");
    Serial.print(address);
    Serial.print("\t");
    Serial.println(val);
 
  }
 
  // Print to Serial Monitor
  Serial.println("Recording Finished!");
 
  // Delay 5 Seconds
  delay(5000);
 
  // Print to Serial Monitor
  Serial.println("Begin Playback...");
 
  // Run until maximum address is reached
 
  for (int address = 0; address <= maxaddress; address++) {
 
    // Read value from EEPROM
    readVal = readEEPROM(address, EEPROM_I2C_ADDRESS);
 
 
    // Write to the servo
    // Delay to allow servo to settle in position
    // Convert value to integer for servo
   
    delay(50);
 
    // Print to Serial Monitor
    Serial.print("ADDR = ");
    Serial.print(address);
    Serial.print("\t");
    Serial.println(readVal);
 
  }
 
  // Print to Serial Monitor
  Serial.println("Playback Finished!");
 
}
 
void loop()
{
 
  // Nothing in loop
 
}
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: Multiple i2c port drive & Multiple SPI port drive

Post by stevestrong »

Have you tried to run the I2C scanner with the second I2C port?
Does it recognize your EEPROM? On which address?
madhavan
Posts: 29
Joined: Fri May 21, 2021 1:22 am

Re: Multiple i2c port drive & Multiple SPI port drive

Post by madhavan »

hi,
i have tried with scanning and it's detected address as 0x50 & 0x51 .

Do you think I2C_FAST_MODE will be suitable to read the chip address quickly . there is possibility for data read & write in slow mode or something like that .

TwoWire WIRE2 (2,I2C_FAST_MODE);
#define Wire WIRE2
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: Multiple i2c port drive & Multiple SPI port drive

Post by stevestrong »

For slow mode you just leave I2C_FAST_MODE away:

Code: Select all

TwoWire WIRE2 (2);
#define Wire WIRE2
Be sure that you connect to PB10/11 pins.
madhavan
Posts: 29
Joined: Fri May 21, 2021 1:22 am

Re: Multiple i2c port drive & Multiple SPI port drive

Post by madhavan »

hi,

no improvement . value not stored in chip

i have tested the i2c scanning it's detecting in fast mode & normal mode .

13:06:53.946 -> Scanning...
13:06:53.946 -> I2C device found at address 0x50 !
13:06:53.946 -> I2C device found at address 0x51 !
13:06:53.991 -> done .

i have changed the pull up from 3.3k to 4.7k to 10 k but NO improvement .

can you suggest the i2c clock speed changes .

I2C bus Max Speed: 100 Kbit/s.

Stm32 Core - Normal Mode will drive the STM32 blue pill in above speed ?.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: Multiple i2c port drive & Multiple SPI port drive

Post by stevestrong »

I wonder which type of eeprom do you use, is it the same device with two addresses? It is not common...
Have you tried to access the 0x50 address?

The smaller value the pull-up resistor the better, so leave it 3.3k or 2.7k.
But I do not think that this really matters as long as the scanner finds it.

100kbps will be the maximum in normal mode, and should work if the scanner works.
madhavan
Posts: 29
Joined: Fri May 21, 2021 1:22 am

Re: Multiple i2c port drive & Multiple SPI port drive

Post by madhavan »

please suggest best library for using the i2c external eeeprom for page by page writing and reading of 16 bit , float data & string data..
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Multiple i2c port drive & Multiple SPI port drive

Post by fpiSTM »

I'm using regularly this one: https://github.com/PaoloP74/extEEPROM
Post Reply

Return to “General discussion”