Serial EEPROM operation

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Serial EEPROM operation

跳至解决方案
5,182 次查看
AnRes
Contributor I

Hello,

 

I need to display data on screen computer written in a Serial EEPROM. I did a simple test but it does not work. I am using the HCS08QE128 microcontroller SW_I2C bean and I am programming it with CodeWarrior V6.2 (Processor Expert Tool). This is the Main.C code:

 

char mov[]="A B C D E"; 

byte data;
int i;

 

void main(void)
{
  (void)EI2C1_SelectSlave(0x50);
  

  for(i=0;i<sizeof(mov);i++) 
      {

        while(EI2C1_SendChar(mov[i])!= ERR_OK);

        while(EI2C1_RecvChar(&data)!= ERR_OK);

        while(AS1_SendChar(data)!=ERR_OK);
        Cpu_Delay100US(10000);
       }
}

 

The information displayed on the screen is not the written string  "A B C D E" but a string like this "ÿÿÿÿÿÿÿÿÿÿ". I think there is a problem with the variable "data" in functions EI2C1_RecvChar and AS1_SendChar. I really don't know what to do to get the right data in PC screen.  

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
2,515 次查看
ProcessorExpert
Senior Contributor III

The example below shows how to read a data from EEPROM device in a loop.

 

//READ DATA

MAIN.C
 
byte addr;
 
for (addr=50; addr<100; addr++) {
  (void)EI2C1_SelectSlave(0x50);
  buff[0] = addr >> 8;    //most significant address
  buff[1] = addr && 0xff; //least  significant address
  EI2C1_SendBlock(buff, 2, &sent); //send address to the EEPROM
  EI2C1_SendStop();
  EI2C1_RecvChar(&data);  //read data from EEPROM
  EI2C1_SendStop();
}

 

Steps how to install additional bean into Processor Expert are for example here.

 

best regards
Vojtech Filip
Processor Expert Support Team

在原帖中查看解决方案

0 项奖励
回复
7 回复数
2,515 次查看
bigmac
Specialist III

Hello, and welcome to the forum.

 

I assume that you are using the SCI module to output the characters within the external EEPROM.  If so, it would appear that you do not have the correct baud rate setting to match that of the computer serial port.  It is not clear in which function your code does initialise the SCI module.

 

Regards,

Mac

 

0 项奖励
回复
2,515 次查看
AnRes
Contributor I

Hi Mac,

 

There is no problem within the serial communication between the computer serial port and the HSC08 SCI bean. I set the baud rate at 9600b in both devices. When I make "while(ASI_SendChar(65)!=ERR_OK);" in main's code, I get an 'A' displayed on the screen. The problem is that it doesn't occur the same when I send characters read from serial EEPROM. I need to verify by displaying on computer's screen that each character I wrote before in serial EEPROM is really stored there. Also, I know there is neither a problem within communication between the serial EEPROM and the HSC08 I2C bean. When I make "while(EI2C1_SendChar(65)!=ERR_OK);" in main's code I get "ERR_OK" as response, and when I make "while(EI2C1_RecvChar(&Chr)!=ERR_OK);" I get "ERR_OK" again, but after that, when I make "while(ASI_SendChar(Chr)!=ERR_OK);" I get 'ÿ' instead of 'A'.

 

So I think I am making a mistake within the way to pass the argument "&Chr" (pointer to char) in I2C reading method (RecvChar) and within the way to pass the argument "Chr" (pointed character) in SCI sending method (SendChar). Also, I think it could be a problem with the 2 bytes of internal addressing of memory position in serial EEPROM, but if so, how can I know if the address of one written chararcter is kept when I want to read that character and how can I control that to do not read another different memory position? 

 

This is the first time I work with a serial EEPROM (AT24C1024B-PU) and the first time using the I2C bean with Processor Expert Tool. I don`t know what is wrong and which is the correct way to make it works.           

 

Thank you for your help!

0 项奖励
回复
2,515 次查看
ProcessorExpert
Senior Contributor III

Hello,
 
I think that your code post here does note correspond to the communicatio protocol of the EEPROM specified in the datasheet. I don´t see any problem in PE beans.
 
However in case if you have purchased at least Standart CodeWarrior Suite there is the possibility to download the additional software bean (EEPROM_I2C_24xxx) from www.processorexpert.com
that covers the communication with EEPROM device and provides methods to simple read or write data from/to EEPROM.
 
In other case try to run the code bellow:

MAIN.C

  byte buff[3];
  word sent;
  byte data;

  //WRITE DATA

  (void)EI2C1_SelectSlave(0x50);
  buff[0] = 0;     //most significant address
  buff[1] = 0x50;  //least  significant address
  buff[2] = 0x10;  //data
  EI2C1_SendBlock(buff, 3, &sent); //send address and data to the EEPROM
  EI2C1_SendStop();

  //READ DATA
 

  (void)EI2C1_SelectSlave(0x50);
  buff[0] = 0;    //most significant address
  buff[1] = 0x50; //least  significant address
  EI2C1_SendBlock(buff, 2, &sent); //send address to the EEPROM
  EI2C1_SendStop();
  EI2C1_RecvChar(&data);  //read data from EEPROM
  EI2C1_SendStop(); 

 

best regards
Vojtech Filip
Processor Expert Support Team

0 项奖励
回复
2,515 次查看
AnRes
Contributor I

Thank you very much Filip, the code you gave me did work. I run it and now I can see correct characters on the PC screen. Although, I have still a problem. The project I am working in has two devices, the first one monitors MMA7260QT signal and writes data on serial EEPROM, the other one reads data from serial EEPROM and sends it to the PC. Some time after monitoring process ends I have to make an analysis of stored data so I need to get it by reading the whole information from serial EEPROM and showing it on PC screen. I don't know how to do that because the RecvChar method reads only the last character written. I don't know how to place the address pointer over the first position of memory for reading data from the beginning until the last character written. I need your help with this again please!

 

I did download the EEPROM_I2C_24xxx file but I don't know how to use it. I unzipped it and put it on Processor Expert Bean's folder (C:\Archivos de programa\Freescale\CodeWarrior for Microcontrollers V6.2\ProcessorExpert\BEANs) but I can't add the bean in Code Warrior's project.

 

Again, thank you for your time and for your valuable assistance in this topic.

 

Kind Regards,

 

Andrés Gómez           
    

0 项奖励
回复
2,516 次查看
ProcessorExpert
Senior Contributor III

The example below shows how to read a data from EEPROM device in a loop.

 

//READ DATA

MAIN.C
 
byte addr;
 
for (addr=50; addr<100; addr++) {
  (void)EI2C1_SelectSlave(0x50);
  buff[0] = addr >> 8;    //most significant address
  buff[1] = addr && 0xff; //least  significant address
  EI2C1_SendBlock(buff, 2, &sent); //send address to the EEPROM
  EI2C1_SendStop();
  EI2C1_RecvChar(&data);  //read data from EEPROM
  EI2C1_SendStop();
}

 

Steps how to install additional bean into Processor Expert are for example here.

 

best regards
Vojtech Filip
Processor Expert Support Team

0 项奖励
回复
2,515 次查看
AnRes
Contributor I

Hello Filip,

 

After using the last code that you sent me, I got 50 'ÿ's displayed on the PC screen. Again there is a problem within the addressing of memory position in serial EEPROM for reading data.

 

I followed the process of installation a new bean but still I can't add it on my project, it isn't included on the list of beans.

 

Thank you again!

 

Kind Regards,

 

Andrés Gómez

 

0 项奖励
回复
2,515 次查看
ProcessorExpert
Senior Contributor III

I recommend to (if you haven't already done):

- Try that if your serial communication working properly- add sending of some known text to check that

-  Check that the eeprom is properly connected and under power and is returning any data (with oscilloscope)

 

Regarding the installed bean, the bean should be listed in the bean selector (try alphabet tab).

For sure, you can try to switch of the filtering buttons(with cpu name and 'licensed') at the bottom of the Bean Selector. Bu you have at least the standard suite ? Plese note that the free software beans are not available for the free special edition.

 

best regards
Petr Hradsky
Processor Expert Support Team
 

0 项奖励
回复