MATLAB Answers

How to read from a specific part of EEPROM via SPI in R2016a?

68 views (last 30 days)
I am using the C2000 TI support package and I need to set the SPI block to read/write to a specific address in EEPROM.
I am using MATALB R2016a and upgrading is not an option at the moment.
I am using a TMS320F28335 microcontroller and the Microchip is a 25LC128 EEPROM (128kbit)
Is there any workaround that I can use?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 May 2020 at 4:00
Edited: MathWorks Support Team on 18 May 2020 at 17:33
Since the workflow is not directly available in MATLAB R2016a, the best alternative would be to upgrade to a newer release of MATLAB where the whole process will be much easier. This will save you a lot of time. However, if this was not possible, I added a workaround below that might help implementing a custom solution.
The table below summarizes some important differences between SPI blocks in MATLAB R2016a and recent releases.
1. Considering these limitations with MATLAB R2016a you will need to do the following to ensure you can WRITE and READ from EEPROM successfully.
2. In order to WRITE you will first need to send a write sequence as captured below. This involves sending 8 bits of write enable command. Observe the Chip select. It must go high for the operation to complete. Unfortunately, in R2016a we cannot use multiple instances of the block. Hence this initialisation command needs to be performed in a custom code block by writing the c-code such that we write the SPI TX FIFO buffer with your WRITE ENABLE command. Please note that you will have to implement a while loop to wait on the SPI Rx buffer to discard the dummy byte & de-assert the chip select if needed. Refer point 7 below.
3. During runtime, when we need to send the Bytes for write using WRITE command i.e below sequence:
You can use the SPI Tx block and byte pack the data values to send them as packets of 1 byte each. How to achieve this can be studied from the models at this page:
4. You will be sending the data as packets of 1 byte each, so in the configuration select the number of bits as 8.
5. You should ensure to also use a SPI read block to discard the dummy data that comes in during Write operation to keep Rx FIFO clean. Refer to point 7
6. Since only one instance of the block is available, you need to design the logic around Rx and Tx blocks such that when the write operation is needed, the Tx block transmits the write command and related data and Rx block discards the received dummy data. For reading, the Tx block now sends the read command & dummy bytes, while the read block reads the actual data.
7. Also please note, Tx and Rx operations must be used together. Tx asserts the Chip select and begins transmitting, while the Rx de-asserts the chip select and reads the data. Hence, they both together achieve one SPI data transfer sequence.
8. The same description holds true when reading the data for the below operation.

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.