Hello,
If you have two SPI slave devices in the same project, the low-side driver and the EEPROM, you will require a separate CS (SS) line for each device. If the driver requires the delays to be present, it is not necessary to include them for the EEPROM also. It is quite possible that the SPI will need to be set up differently for each device, so you would run the relevant initialisation function prior to communicating with a particular device.
The initialisation that PE generates is not clear, and may not be correct for the EEPROM. The CPOL,CPHA settings will need to be either 0,0 or 1,1. Of course, you will not be able to use the automatically generated SS signal (if available for the SPI module).
I am not sure what an SPIF flag is because it isn't listed in the SPI SPCR as well as SPSCR registers. Did u mean the SPRF flag and the SPDR need to be read again to clear this flag after sending the char ?
Yes, SPRF is another name for the same flag. However, the SM1_SendChar() function generated by PE does not wait for this flag to be set, so it is problematic to raise CS when this function exits. This function seems to be overly complicated for the task in hand, since your code would need to be able to specifically handle each error return. For SPI operation using higher clock rates, I usually prefer to simply wait until the required flag becomes set - generally only a few microseconds at most.
could it be that since SPI sends MSB first, does the bits need to be reversed in order that they are received in the correct order at the other end ?
MSB first is correct for the EEPROM device.
Also,if it takes 10 ms for a write a cycle, does it mean that it will take 100 ms to write 10 bytes ?
Yes, if you write ten individual bytes. However, if you use the "page write" mode for ten consecutive bytes within the same page, the process would take 10ms.
if i read back char, how do i convert them to int to do calculations ? does atoi function still work in this compiler?
Each data read back from the EEPROM will be a 8-bit binary value, in exactly the same format as the data was originally written. It the data type stored requires more than 8 bits, multiple byte writes and reads will be required for each data element.
Regards,
Mac