cancel
Showing results for 
Search instead for 
Did you mean: 

FM24C256 FRAM programming (STM32F0xx-DISCOVERY Board)

schubertjw
Associate II
Posted on June 03, 2015 at 09:42

Hello dear members of forum,

I would like to use a FM24C256 ram of RAMTRON (

http://www.kosmodrom.com.ua/data/memory/FM24C256ds_r3.1.pdf

). I have tryed to write program for it but It do not work. When I write it the program to stop at the red line. Please help me. I am waiting for your advise. My program is:

#define FM_SCK GPIO_Pin_10
#define FM_SDA GPIO_Pin_11
#define FM_SCKPS GPIO_PinSource10
#define FM_SDAPS GPIO_PinSource11
#define FM_GAF GPIO_AF_1
#define FM_GPIO GPIOB
#define FM_I2C I2C2
#define DS_ADDR (0x68<<
1
)
#define I2C_CLK 1000000
#define FRAM_ADDR_WR 0xA0 
#define FRAM_ADDR_RD 0xA1 
#define FRAM_SIZE 32768 
#define I2C_WR_ACK 0 // ACK state when writing 
#define I2C_RD_NAK 0 // CCS value to NAK on read 
#define I2C_RD_ACK 1 // CCS value to ACK on read 
extern void fram_init(void);
extern uint8_t I2C_FMWrReg(uint16_t Reg, uint8_t data);
uint8_t I2C_FMRdReg(uint16_t start_addr);
void fram_init(void)
{
GPIO_InitTypeDef G;
I2C_InitTypeDef I;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);
G.GPIO_Pin
= 
FM_SDA
| FM_SCK;
G.GPIO_OType
= 
GPIO_OType_OD
;
G.GPIO_PuPd
= 
GPIO_PuPd_UP
;
G.GPIO_Speed
= 
GPIO_Speed_Level_1
;
G.GPIO_Mode
= 
GPIO_Mode_AF
;
GPIO_Init(FM_GPIO, &G);
GPIO_PinAFConfig(FM_GPIO, FM_SDAPS, FM_GAF);
GPIO_PinAFConfig(FM_GPIO, FM_SCKPS, FM_GAF);
I.I2C_Ack
= 
I2C_Ack_Enable
;
I.I2C_AcknowledgedAddress
= 
0x00
;
I.I2C_AnalogFilter
= 
I2C_AnalogFilter_Enable
;
I.I2C_DigitalFilter
= 
0x00
;
I.I2C_Mode
= 
I2C_Mode_I2C
;
I.I2C_OwnAddress1
= 
0x01
;
I.I2C_Timing
= 
0x10805F87
;
I2C_Init(FM_I2C, &I);
I2C_Cmd(FM_I2C, ENABLE);
}
uint8_t I2C_FMWrReg(uint16_t start_addr, uint8_t data){
while(I2C_GetFlagStatus(FM_I2C, I2C_FLAG_BUSY) == SET); // to controll busy
I2C_TransferHandling(FM_I2C, FRAM_ADDR_WR, 1, I2C_Reload_Mode, I2C_Generate_Start_Write); // to send start bit and wait for setting
while(I2C_GetFlagStatus(FM_I2C, I2C_FLAG_TXIS) == RESET);
I2C_SendData(FM_I2C, start_addr>>8); // to send address HIGH
while(I2C_GetFlagStatus(FM_I2C, I2C_FLAG_TCR) == RESET);
I2C_TransferHandling(FM_I2C, DS_ADDR, 1, I2C_AutoEnd_Mode, I2C_No_StartStop); // to send acknowledment bit
while(I2C_GetFlagStatus(FM_I2C, I2C_FLAG_TXIS) == RESET);
I2C_SendData(FM_I2C, start_addr); // to send address LOW 
while(I2C_GetFlagStatus(FM_I2C, I2C_FLAG_TCR) == RESET);
I2C_TransferHandling(FM_I2C, DS_ADDR, 1, I2C_AutoEnd_Mode, I2C_No_StartStop); // to send acknowledment bit
while(I2C_GetFlagStatus(FM_I2C, I2C_FLAG_TXIS) == RESET); 
I2C_SendData(FM_I2C, data); // to send data
while(I2C_GetFlagStatus(FM_I2C, I2C_FLAG_STOPF) == RESET); 
I2C_ClearFlag(FM_I2C, I2C_FLAG_STOPF); // to send end bit
}
uint8_t I2C_FMRdReg(uint16_t start_addr){
uint8_t data;
while(I2C_GetFlagStatus(FM_I2C, I2C_FLAG_BUSY) == SET);
I2C_TransferHandling(FM_I2C, FRAM_ADDR_WR, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
while(I2C_GetFlagStatus(FM_I2C, I2C_FLAG_TXIS) == RESET);
I2C_SendData(FM_I2C, start_addr>>8);
while(I2C_GetFlagStatus(FM_I2C, I2C_FLAG_TC) == RESET);
I2C_TransferHandling(FM_I2C, FRAM_ADDR_WR, 1, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
while(I2C_GetFlagStatus(FM_I2C, I2C_FLAG_RXNE) == RESET);
I2C_SendData(FM_I2C, start_addr);
while(I2C_GetFlagStatus(FM_I2C, I2C_FLAG_TC) == RESET);
I2C_TransferHandling(FM_I2C, FRAM_ADDR_WR, 1, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
while(I2C_GetFlagStatus(FM_I2C, I2C_FLAG_RXNE) == RESET);
data = I2C_ReceiveData(FM_I2C);
while(I2C_GetFlagStatus(FM_I2C, I2C_FLAG_STOPF) == RESET);
I2C_ClearFlag(FM_I2C, I2C_FLAG_STOPF);
return data;
}

10 REPLIES 10
Posted on June 03, 2015 at 13:21

Did you have a look at the I2C bus with an oscilloscope/LA?

Btw., the FRAM from the I2C bus point of view is no different from any other I2C EEPROM (any 24Cxxx). Oh, and there is no Ramtron anymore... (it's Cypress now, ).

JW
schubertjw
Associate II
Posted on June 03, 2015 at 13:33

Hello JW,

Thank you so mach for your answer. I do not look I2c bus with scope becuse I not have any. So if it is possible can you look my program is good? Or if you have a good version I should thanks to send me it.

Best regards,

Suby

Further: RAMTRON... Sorry I di not know that the name was changed. 🙂

stm32forum
Associate II
Posted on June 03, 2015 at 14:36

How did you connect the the chip, any pull up resistors?

The ramtron has a minimum operation voltage of 4.5V.

schubertjw
Associate II
Posted on June 03, 2015 at 14:44

Hello,

Thanks for your attendance. Yes of course, I use two pull up resistors(2,7K). So I think it is ready.

Best regards,

Suby

Posted on June 03, 2015 at 14:48

No oscilloscope? Get one, or borrow one, it's important to see what you are doing.

Meantime, you can avoid using the I2C module in the mcu and bit-bang the I2C. And if you have a debugger, you can do it literally manually writing directly to registers in the debugger - switch on GPIO clock in RCC, set the two pins to open collector, output, then manipulate the output values as per I2C protocol and watch the input states. It's fun 😉

JW

EDIT PS. The name - semiconductor companies buy each other all the time and then it's hard to keep track where did all those chips move. This is why I maintain http://www.efton.sk/t0t1/semic_change.htm 🙂
schubertjw
Associate II
Posted on June 03, 2015 at 15:06

Dear JW,

Thank you for your advice. I will try to borrow one... 🙂

Best regards,

Suby

stm32forum
Associate II
Posted on June 03, 2015 at 20:24

Or buy for $10 a

http://www.dx.com/p/logic-analyzer-w-dupont-lines-and-usb-cable-for-scm-black-148945

, with the software you can analyze the i2c bus.

schubertjw
Associate II
Posted on June 03, 2015 at 21:11

It is a good idea. Thanks.... I will order one...........

schubertjw
Associate II
Posted on June 05, 2015 at 23:32

Dear members,

Thanks so much for helping to everibody. My program works well with FM24C256. The writing and reading are perfect.

Best regards,

Suby