How Psoc to access external 24C01 EEPROM device

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
MoSh_333906
Level 2
Level 2

Hi sir,

   

I can find the EZI2C device in Psoc but it is slave one.

   

Can we have a way to access  external 24C01 EEPROM  device?

   

Maybe I2C device can do this but I tried before and failed because

   

I don't know how to simulate the base address different to slave address in I2C master device.

   

We need device address and base address when access to 24C01.

   

It is much appreciated if someone can suggest how to do this.

   

Thanks

   

Best regards,

   

Morris

0 Likes
1 Solution
MoSh_333906
Level 2
Level 2

Hi Bob,

   

I have fixed the issue today. The previous issue is caused by I2C internal write delay.

   

This causes I2C bus lost connection or other bus error.

   

Replace " status = I2C_MasterSendStart(0x50, I2C_WRITE_XFER_MODE); " by the following code

   

/***** new modified code ****/

   

status = I2C_MasterSendStart(0x50, I2C_WRITE_XFER_MODE);
        
         while ( status !=I2C_MSTR_NO_ERROR )
        {
          I2C_MasterSendStop(); // Send Stop 
          status = I2C_MasterSendStart(0x50, I2C_WRITE_XFER_MODE); 
        }

   

/****              ****/

   

Anyway appreciate your great support.

   

Best regards,

   

Morris

View solution in original post

0 Likes
10 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum.

   

Use the I2C component and configure it as master. Some more is explained here.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
MoSh_333906
Level 2
Level 2

Hi Bob,

   

Thanks for the reply. I tried it but failed. The part 24C01 device address is 0x50-0x57 dependent on external pin 1,2,3 setting.

   

ex,  I run this "  status = I2C_MasterSendStart(0x50, I2C_WRITE_XFER_MODE); " instruction.

   

The 24C01 acknowledges the cycle but  "  status = I2C_MasterSendStart(0x00, I2C_WRITE_XFER_MODE); "

   

24C01 doesn't ACK this cycle.

   

Thanks and best regards,

   

Morris

0 Likes
MoSh_333906
Level 2
Level 2

Hi Bob,

   

Forget to send the original source file. You may confuse to read this png file.

   

Following are the main file list for your reference.

   

 

   

#include "project.h"

   

uint8 status;

   

uint8 i;

   

uint8 wrArray[5]={0,1,2,3,4};

   

uint8 rdArray[5];

   

int main(void)

   

{

   

CyGlobalIntEnable; /* Enable global interrupts. */

   

// Place your initialization/startup code here (e.g. MyInst_Start())

   

I2C_Start();

   

for(;;)

   

{

   

I2C_MasterClearStatus();

   

status = I2C_MasterSendStart(0x50, I2C_WRITE_XFER_MODE);

   

if(I2C_MSTR_NO_ERROR == status) /* Check if transfer completed without errors */

   

{

   

/* Send array of 2 bytes */

   

for(i=0; i<2; i++)

   

{

   

status = I2C_MasterWriteByte(wrArray);

   

if(status != I2C_MSTR_NO_ERROR)

   

{

   

break;

   

}

   

}

   

}

   

I2C_MasterSendStop(); /* Send Stop */

   

I2C_MasterClearStatus();

   

status = I2C_MasterSendStart(0x50, I2C_READ_XFER_MODE);

   

if(I2C_MSTR_NO_ERROR == status) /* Check if transfer completed without errors */

   

{

   

/* Read array of 2 bytes */

   

for(i=0; i<2; i++)

   

{

   

if(i < 1)

   

{

   

rdArray = I2C_MasterReadByte(I2C_ACK_DATA);

   

}

   

else

   

{

   

rdArray = I2C_MasterReadByte(I2C_NAK_DATA);

   

}

   

}

   

}

   

I2C_MasterSendStop(); /* Send Stop */

   

return 0;

   

}

   

Explanations on main program:

   

1) Write 2 bytes on slave device address 0x50. First byte is 0x00 and scecond is 0x01.

   

2) Read 1 byte  on the same device address 0x50 but not ACK by 24C01.

   

One more question is why 24C01 doesn't acknowledge this read with correct address.

   

Thanks

   

Best regards,

   

Morris

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Sorry, but I do not read code snippets without the help of the IDE.  Use

   

Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file. Can you provide me with a link to your EEProm datasheet, mine didn't show up your I2C address.

   

 

   

Bob
 

0 Likes
lock attach
Attachments are accessible only for community members.
MoSh_333906
Level 2
Level 2

Hi Bob,

   

The attached are the source file , waveform png file  and data sheet for your reference.

   

procedure :

   

1) write device address 0x50 with data 0 & 1. [ to implement  the data sheet Figure 8. Byte Write ]

   

2) dummy write address 0x50 with address 0 using write data 0.

   

3) Read address 0x50. [ 2) & 3) to implement the data sheet Figure 11. Random Read ]

   

Thanks

   

Best regards,

   

Morris

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

After your first sendstart you do not write two bytes, the first byte is the page number where the data is going to.

   

Putting all into a single transaction using sendrestart() might fail afaik the device needs a stop condition to perform the actual write.

   

What kind of board are you using?

   

 

   

Bob

0 Likes
MoSh_333906
Level 2
Level 2

Hi Bob,

   

Thanks.

   

It is still unclear to me. Can you give me a sample code to test?

   

Ex, write base address 0 with 0x55 and read back again to verify data correctness.

   

The board I test is CY8CKIT-050.

   

Best regards,

   

Morris

0 Likes
lock attach
Attachments are accessible only for community members.
MoSh_333906
Level 2
Level 2

Hi Bob,

   

Update two project files. One is page write and one for random read.

   

Page write also works for Byte write in special case. I can run these two programs in separate successfully

   

Only one problem is I can't run these two programs in one main file.

   

By the way, I also use Arduino I2C supported function to access this 24C01. And it works fine.

   

Arduino program performs writ and read in one program.

   

This is the only question I have now. Can you help check this?

   

Thanks

   

Best regards,

   

Morris

0 Likes
MoSh_333906
Level 2
Level 2

Hi Bob,

   

I have fixed the issue today. The previous issue is caused by I2C internal write delay.

   

This causes I2C bus lost connection or other bus error.

   

Replace " status = I2C_MasterSendStart(0x50, I2C_WRITE_XFER_MODE); " by the following code

   

/***** new modified code ****/

   

status = I2C_MasterSendStart(0x50, I2C_WRITE_XFER_MODE);
        
         while ( status !=I2C_MSTR_NO_ERROR )
        {
          I2C_MasterSendStop(); // Send Stop 
          status = I2C_MasterSendStart(0x50, I2C_WRITE_XFER_MODE); 
        }

   

/****              ****/

   

Anyway appreciate your great support.

   

Best regards,

   

Morris

0 Likes
MoSh_333906
Level 2
Level 2

This code had better apply all the  I2C_MasterSendStart() function for read / write access to recover

   

possible I2C bus error.

   

Best regards,

   

Morris

0 Likes