We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello. I need some help. I'm trying to write, read and erase an external EEPROM (25AA040 MICROCHIP) via SPI from XC164CS board, for example, one byte at 0x00 adress of the eeprom, but i don't know how to do it. Into the datasheet, I can see some instructions but i don't know what to do with them: img28.imagevenue.com/img.php Could anyone help me? Thank you very much. :)
#ifndef _SSC0_H #define _SSC0_H 1 typedef enum { WRSR = 0x0100, /* Write Status Register */ WRITE = 0x0200, /* Write Data to Memory Array */ READ = 0x0300, /* Read Data from Memory Array */ WRDI = 0x0400, /* Reset Write Enable Latch */ RDSR = 0x0500, /* Read Status Register */ WREN = 0x0600, /* Set Write Enable Latch */ } EepromCommandType; enum eepromStatus { RDY_ = 0x01, /* "1" indicates the write cycle is in progress */ WEN = 0x02, /* "1" indicates the device is WRITE ENABLED */ BP0 = 0x04, /* protection range */ BP1 = 0x08, /* protection range */ WPEN = 0x80, /* Write enable see data sheet table */ }; typedef struct { EepromCommandType cmd; U8 hb; U8 lb; volatile BoolFalseTrueType busy; U16 bytesRx; U16 bytesTx; U16 txCnt; S8 *txptr; U16 rxCnt; S8 *rxptr; S8 data; S8 *baseptr; } EEPROM_CONTROL_TYPE; /* prototypes */ void SSC0_Init(void); void ASC0_vInit(void); U8 EepromRead(U16 address, S8 *des, U16 cnt, U16 my_adress2); U8 EepromWrite(U16 address, S8 *src, U16 cnt, U16 my_adress1); U8 EepromReadStatus(U16 my_adress1); U8 EepromBusy(void); U8 EepromWriteEnable(U16 my_adress1); /* interrupt vector numbers */ #define SSC0TINT 0x2D #define SSC0RINT 0x2E #define ASC0_TBINT 0x47 #define ASC0_RINT 0x2B #endif /* ifndef _SSC0_H */
didn't you say that 'EepromStartTx' cannot be changed without disabling your EEPROM? let me ask again: post the modified version of it, and only that function, that does not work. that is the source of the problem, isn't it (at least, according to you)?
In opinion of Chris, only the enum EepromCommandType must be changed (I have already changed it) and modify the start address of pointer, but i don't know how to do it. This is the modified version by me.
_inline void EepromStartTx(U16 MY_ADRESS) { CS_EEPROM = low; eeprom.bytesTx = 1; /* decrement the transmit count by one */ eeprom.bytesRx = 0; eeprom.txptr = (S8 *)(&eeprom)+MY_ADRESS; /* reset pointer to first element */ SSC0_TB = *eeprom.txptr++; /* write the first byte to the SSC0 tx buffer */ }
Hello, Tamir, Chris, my nigthmare has ended. I have tested the last configuration of Chris, and the program works perfectly. I read /write the bytes in the wished address. It isn't necessary to add a new parameter in the EepromStartTx function. Only the pointer has to be increased by 1.
_inline void EepromStartTx() { CS_EEPROM = low; eeprom.bytesTx = 1; /* decrement the transmit count by one */ eeprom.bytesRx = 0; eeprom.txptr = (S8 *)(&eeprom) + 1; /* reset pointer to first element */ SSC0_TB = *eeprom.txptr++; /* write the first byte to the SSC0 tx buffer */ }
Thanks very much for your help.