- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have written a program to write and read data from FRAM and display it through UART. I am not able to make out where I have gone wrong since I am new to PSoC controllers. I have attached my code for your reference. I have tried both the method to write and read data from FRAM. Kindly help me as soon as possible.
Thank You
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi MKN_4249821,
I tested both your projects using our 4200 M pioneer kit. This kit has Cypress I2C F- RAM (FM24V10) in it. It is a 128K nonvolatile memory with 16 bit addressing.
I2C_FRAMTest01:
1. I think that you want to store the data "hello" in some location but you have not mentioned to which location you wanted to write.
2. I2C master write complete needs to checked to proceed further with the I2C operation
while(0u == (I2C_I2CMasterStatus() & I2C_I2C_MSTAT_WR_CMPLT))
{
}
Your previous code would have failed in the while loop in the first try and would have not written into the memory location
Modified code:
writeBuf[0] = 0x00; //Address MSB
writeBuf[1] = 0x00; //Address LSB
writeBuf[2] = 'h';
writeBuf[3] = 'e';
writeBuf[4] = 'l';
writeBuf[5] = 'l';
writeBuf[6] = 'o';
if(I2C_I2C_MSTR_NO_ERROR == I2C_I2CMasterWriteBuf(0x50,writeBuf, 7, I2C_I2C_MODE_COMPLETE_XFER))
{
while(0u == (I2C_I2CMasterStatus() & I2C_I2C_MSTAT_WR_CMPLT))
{
}
/* Wait until master complete write. If the Master lost arbitration, stop waiting. */
if (0u == (I2C_I2CMasterStatus() & I2C_I2C_MSTAT_ERR_XFER))
{
/* Check if all bytes were written */
if (I2C_I2CMasterGetWriteBufSize() == 5)
{
UART_UartPutString("I2C Write over\r\n");
}
}
}
Same applies for read transaction :
if(I2C_I2C_MSTR_NO_ERROR == I2C_I2CMasterWriteBuf(0x50, writeBuf, 2, I2C_I2C_MODE_NO_STOP))
{
while(0u == (I2C_I2CMasterStatus() & I2C_I2C_MSTAT_WR_CMPLT))
{
}
/* Wait until master complete write. If the Master lost arbitration, stop waiting. */
if(I2C_I2C_MSTR_NO_ERROR ==I2C_I2CMasterReadBuf(0x50, readBuf, 5, I2C_I2C_MODE_REPEAT_START))
{
while(0u == (I2C_I2CMasterStatus() & I2C_I2C_MSTAT_RD_CMPLT))
{
}
if (0u == (I2C_I2C_MSTAT_ERR_XFER & I2C_I2CMasterStatus()))
{
if(I2C_I2CMasterGetReadBufSize() == 5)
{
UART_UartPutString("I2C Read Over \n\r Result: ");
UART_UartPutString((char *)readBuf);
UART_UartPutString("\r\n");
}
}
}
}
The above code worked at my end and the following is the output:
I2C_FRAMTest02:
I did not modify anything in the code. I just sent two bytes for address (0x0000). The code just worked.
I'm attaching both the projects for your reference.
Debugging steps:
1. Check the device slave address
2. Check if it is 8 bit or 16 bit addressing for the memory locations in the FRAM
3. See if you have chosen the right pull up resistors for the I2C lines. Refer NXP I2C spec
4. Check the slave datasheet and see if you are missing any sequence
5. Probe the I2C lines and check what is actually happening in the bus
Note: If you are using Cypress F-RAM device, we recommend you to use serialNVRAM component which makes your job easier. Refer to the following code example to learn the component:
https://www.cypress.com/documentation/code-examples/ce220500-interfacing-i2c-f-ram-psoc-4
Regards,
Bragadeesh
Bragadeesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi MKN_4249821,
I tested both your projects using our 4200 M pioneer kit. This kit has Cypress I2C F- RAM (FM24V10) in it. It is a 128K nonvolatile memory with 16 bit addressing.
I2C_FRAMTest01:
1. I think that you want to store the data "hello" in some location but you have not mentioned to which location you wanted to write.
2. I2C master write complete needs to checked to proceed further with the I2C operation
while(0u == (I2C_I2CMasterStatus() & I2C_I2C_MSTAT_WR_CMPLT))
{
}
Your previous code would have failed in the while loop in the first try and would have not written into the memory location
Modified code:
writeBuf[0] = 0x00; //Address MSB
writeBuf[1] = 0x00; //Address LSB
writeBuf[2] = 'h';
writeBuf[3] = 'e';
writeBuf[4] = 'l';
writeBuf[5] = 'l';
writeBuf[6] = 'o';
if(I2C_I2C_MSTR_NO_ERROR == I2C_I2CMasterWriteBuf(0x50,writeBuf, 7, I2C_I2C_MODE_COMPLETE_XFER))
{
while(0u == (I2C_I2CMasterStatus() & I2C_I2C_MSTAT_WR_CMPLT))
{
}
/* Wait until master complete write. If the Master lost arbitration, stop waiting. */
if (0u == (I2C_I2CMasterStatus() & I2C_I2C_MSTAT_ERR_XFER))
{
/* Check if all bytes were written */
if (I2C_I2CMasterGetWriteBufSize() == 5)
{
UART_UartPutString("I2C Write over\r\n");
}
}
}
Same applies for read transaction :
if(I2C_I2C_MSTR_NO_ERROR == I2C_I2CMasterWriteBuf(0x50, writeBuf, 2, I2C_I2C_MODE_NO_STOP))
{
while(0u == (I2C_I2CMasterStatus() & I2C_I2C_MSTAT_WR_CMPLT))
{
}
/* Wait until master complete write. If the Master lost arbitration, stop waiting. */
if(I2C_I2C_MSTR_NO_ERROR ==I2C_I2CMasterReadBuf(0x50, readBuf, 5, I2C_I2C_MODE_REPEAT_START))
{
while(0u == (I2C_I2CMasterStatus() & I2C_I2C_MSTAT_RD_CMPLT))
{
}
if (0u == (I2C_I2C_MSTAT_ERR_XFER & I2C_I2CMasterStatus()))
{
if(I2C_I2CMasterGetReadBufSize() == 5)
{
UART_UartPutString("I2C Read Over \n\r Result: ");
UART_UartPutString((char *)readBuf);
UART_UartPutString("\r\n");
}
}
}
}
The above code worked at my end and the following is the output:
I2C_FRAMTest02:
I did not modify anything in the code. I just sent two bytes for address (0x0000). The code just worked.
I'm attaching both the projects for your reference.
Debugging steps:
1. Check the device slave address
2. Check if it is 8 bit or 16 bit addressing for the memory locations in the FRAM
3. See if you have chosen the right pull up resistors for the I2C lines. Refer NXP I2C spec
4. Check the slave datasheet and see if you are missing any sequence
5. Probe the I2C lines and check what is actually happening in the bus
Note: If you are using Cypress F-RAM device, we recommend you to use serialNVRAM component which makes your job easier. Refer to the following code example to learn the component:
https://www.cypress.com/documentation/code-examples/ce220500-interfacing-i2c-f-ram-psoc-4
Regards,
Bragadeesh
Bragadeesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Bragadeesh,
Thank you for your time It helped me a lot. I hope your support in future.