Example for read/write 24AA02 eeprom

Post here first, or if you can't find a relevant section!
Post Reply
goran.mahovlic
Posts: 35
Joined: Fri May 26, 2017 9:01 pm

Example for read/write 24AA02 eeprom

Post by goran.mahovlic » Sun Jul 16, 2017 11:38 am

I have stm32f103RCT CPU and cannot get 24AA02 eeprom working.
http://ww1.microchip.com/downloads/en/D ... 21709c.pdf
Is there any HAL sample for DMA or IT memory read that is working, so I can test.
All code I have tried stops because does not receive interrupt from I2C.
Pullups are ok.
My STM32 board is connected to raspberry so I can program it with rap GPIOS.
I have rasp connected to same eeprom and from rasp I can read it and write it.
Tested connection and STM is connected to eeprom...

goran.mahovlic
Posts: 35
Joined: Fri May 26, 2017 9:01 pm

Re: Example for read/write 24AA02 eeprom

Post by goran.mahovlic » Sun Jul 16, 2017 11:50 am

It hangs here
EEPROM_ReadWriteFailed.png
EEPROM_ReadWriteFailed.png (110.64 KiB) Viewed 163 times
Sample for I2C scan would help if someone have it?

danieleff
Posts: 302
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: Example for read/write 24AA02 eeprom

Post by danieleff » Sun Jul 16, 2017 1:32 pm

goran.mahovlic wrote:
Sun Jul 16, 2017 11:50 am
Sample for I2C scan would help if someone have it?

Code: Select all

Serial.begin(115200);
    Serial.println("Starting");
    Wire.begin();

    for(int address=0; address<128; address++) {
        Serial.print(address);

        Wire.beginTransmission(address);
        Wire.write(0);

        if (Wire.endTransmission() == 0) {
            Serial.println(": FOUND SOMETHING!!!");
        } else {
            Serial.println(": nothing to see here");
        }
    }
If this hangs, it is possible that pullups are actually not OK. What board are you using? Which pins?

goran.mahovlic
Posts: 35
Joined: Fri May 26, 2017 9:01 pm

Re: Example for read/write 24AA02 eeprom

Post by goran.mahovlic » Sun Jul 16, 2017 3:43 pm

I could try this sample in arduino, but I last time I had some problems with this chip and arduino support ...
So now I am using cubeMX and for now all serial are working and interrupts, but did not manage to get I2C to work.
It would be great if I manage to get arduino on this board cause then I already have code that I need...
This is STM32F103RTC 64 pins CPU.
I did try some HAL based I2C scanner but does not find nothing on bus.
Will need to check with scope is it sending something or there is some problem with that to...

goran.mahovlic
Posts: 35
Joined: Fri May 26, 2017 9:01 pm

Re: Example for read/write 24AA02 eeprom

Post by goran.mahovlic » Sun Jul 16, 2017 4:23 pm

Ok I manage to get blink led from arduino working.
But I need to redefine serial to PB6 PB7 (I have those pins connected to rasp serial)
How can I do that in board.cpp I have this
{&gpiob, &timer4, NULL, 6, 1, ADCx}, /* PB6 */
{&gpiob, &timer4, NULL, 7, 2, ADCx}, /* PB7 */

zmemw16
Posts: 1265
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: Example for read/write 24AA02 eeprom

Post by zmemw16 » Sun Jul 16, 2017 8:34 pm

well that explains no i2c.

temporarily move that serial connection, as you have 'working' serial - maybe on to usart2 pa2 &pa3
did hal give you the send and receive functions ?
there are lots of projects and examples in the repository directory, there's a rather too wide html description of them in there as well. lots of horizontal scrolling, then vertically to look at what it is that's ticked.

now try the i2c scanner again, look on github and do a search 'stm32 hal i2c scanner' gives this
https://github.com/ProjectsByJRP/stm32_hal_i2c_bus_scan

iirc for i2c usage, hal gives the data structures, but you need to add some extra routines for specific device handling, explicit initialisation for the device, then send command, read status, read & write operations- byte, multi-byte etc.

stephen

goran.mahovlic
Posts: 35
Joined: Fri May 26, 2017 9:01 pm

Re: Example for read/write 24AA02 eeprom

Post by goran.mahovlic » Sun Jul 16, 2017 8:57 pm

I did try exactly that I2C scanner and did not get any answer from eeprom just .
..................................................................................................................
will try tomorrow with arduino and some other serial...

I just tried to make std code for reading eeprom, so I will check that to.

I did already used CubeMx DMA I2C and it was easy on another board (STM32L0) but this one gives me just trouble :?

goran.mahovlic
Posts: 35
Joined: Fri May 26, 2017 9:01 pm

Re: Example for read/write 24AA02 eeprom

Post by goran.mahovlic » Mon Jul 17, 2017 7:08 pm

Got it working
I connected usb-serial adapter to serial1, and got serial working.
Tried HardWire but does not work (probably on bad pins)
With Wire (changed pins in Wire.h) and got devices on bus

Scanning...
I2C device found at address 0x50
I2C device found at address 0x51
I2C device found at address 0x52
I2C device found at address 0x53
I2C device found at address 0x54
I2C device found at address 0x55
I2C device found at address 0x56
I2C device found at address 0x57
done

So there is no hardware fault., and that is good :)

But now I need to change Serial to work on my pins (this is important part cause I need serial communication with rasp and board is rasp shield)
I do not need usb emulated serial just serial.
HardWire would be good but not mandatory.

If someone can guide me how to remap first serial that would be great.

And now I really do not know why cubeMx i2c make me trouble but if I fix peripheral to suit my that will be good starting point...

my first serial is on PB6(TX) PB7(RX)
I2C is PB8(SCL) PB9(SDA)

I see there is boards.h with

#define BOARD_USART1_TX_PIN PA9
#define BOARD_USART1_RX_PIN PA10

and probably need to change board.cpp

{&gpioa, &timer1, NULL, 9, 2, ADCx}, /* PA9 */
{&gpioa, &timer1, NULL, 10, 3, ADCx}, /* PA10 */

I did try but was not successful :(

goran.mahovlic
Posts: 35
Joined: Fri May 26, 2017 9:01 pm

Re: Example for read/write 24AA02 eeprom

Post by goran.mahovlic » Thu Jul 20, 2017 4:42 pm

ok getting somewhere

in board.cpp I have added

void boardInit(void) {
afio_remap(AFIO_REMAP_USART1); // remap Serial1(USART1)PB6/PB7
}

and got something on serial - so I assume I need to setup some timer while printing on Serial I have large delay and broken data ...
something.png
something.png (14.59 KiB) Viewed 77 times
on other serial I get normal data, but same speed (slow)
Serial1.png
Serial1.png (16.15 KiB) Viewed 77 times

goran.mahovlic
Posts: 35
Joined: Fri May 26, 2017 9:01 pm

Re: Example for read/write 24AA02 eeprom

Post by goran.mahovlic » Fri Jul 21, 2017 6:18 pm

Ok, remap was just enough ...
But I added some problems with raspberry serial while working on something else.
So now I have two serial port working ;)
working.png
working.png (149.83 KiB) Viewed 54 times

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests