SLAA908A September   2019  – September 2021 MSP430FR2032 , MSP430FR2032 , MSP430FR2033 , MSP430FR2033 , MSP430FR2153 , MSP430FR2153 , MSP430FR2155 , MSP430FR2155 , MSP430FR2310 , MSP430FR2310 , MSP430FR2311 , MSP430FR2311 , MSP430FR2353 , MSP430FR2353 , MSP430FR2355 , MSP430FR2355 , MSP430FR2422 , MSP430FR2422 , MSP430FR2433 , MSP430FR2433 , MSP430FR2475 , MSP430FR2475 , MSP430FR2476 , MSP430FR2476 , MSP430FR4131 , MSP430FR4131 , MSP430FR4132 , MSP430FR4132

 

  1.   Trademarks
  2. 1Introduction
  3. 2Implementation
  4. 3UART Message Format
    1. 3.1 Write N Bytes to Slave Device
    2. 3.2 Read N Bytes From Slave Device
    3. 3.3 Repeated Start (Read After Write)
    4. 3.4 Repeated Start (Write After Write)
    5. 3.5 Write to Internal Register
    6. 3.6 Read From Internal Register
  5. 4Internal Registers Available
    1. 4.1 Register Summary
    2. 4.2 Baud Rate Generator (BRG)
    3. 4.3 I2C Bus Clock Rates (I2CClk)
  6. 5Performance
  7. 6Application Examples
    1. 6.1 Test With I2C Slave Device
    2. 6.2 Read and Write EEPROM
  8. 7Reference
  9. 8Revision History

Read and Write EEPROM

This firmware was tested using EEPROM as the I2C slave device to verify the correctness of the firmware by reading and writing the EEPROM. The EEPROM address is 0x50. Figure 6-4 to Figure 6-7 show the read and write format.

GUID-9E3630DC-5D64-4449-ACEE-6FEB76BF11A4-low.pngFigure 6-4 EEPROM Byte Write
GUID-3B11F4C0-20AD-401A-BBBC-D67F8214A7EF-low.pngFigure 6-5 EEPROM Page Write
GUID-6644A512-E9C6-47FF-9549-FA7132CD31F3-low.pngFigure 6-6 EEPROM Random Read
GUID-EB33F1BF-5E0D-4561-8A2F-A7796B4864C1-low.pngFigure 6-7 EEPROM Sequential Read

The firmware first sets the I2C clock frequency to 100 kHz and sets the UART baud rate to 115200 by writing the internal registers (Figure 6-8 shows the UART commands to read and write the internal register values). For the write test, the firmware writes 64 bytes of data to the EEPROM starting at address 0x0000. For the read test, the firmware reads 64 bytes of data starting at address 0x0000.

Figure 6-8 shows the UART data commands to write to and read from the internal registers.

The write command is composed of these bytes:

  • The first byte is 'W' (0x57) to indicate a write to internal registers
  • The second byte is the internal register start address to write
  • The next four bytes are the data to write
  • The last byte is 'P' (0x53) to indicate stop

The read command is composed of these bytes:

  • The first byte is 'R' (0x52) to indicate a read from internal registers
  • The next four bytes are the addresses to read (0x00, 0x01, 0x02, 0x03)
  • The last byte is 'P' (0x53) to indicate stop

The final four bytes in the last row of Figure 6-8 are the values of the registers specified in the read command.

GUID-3FA49350-424D-47E8-8F9D-1FA3CE4AD143-low.pngFigure 6-8 Write and Read Internal Register (Set I2C Clock Frequency and UART Baud Rate)

Figure 6-9 shows the UART commands to read and write the EEPROM.

The write command is composed of these bytes:

  • The first byte is 'S' (0x53) to indicate an I2C start
  • The second byte is the EEPROM I2C address and write command (0x50 << 1 | 0 = 0xA0)
  • The next three bytes is the length of the write data (0x42), which includes the 2-byte address plus the number of bytes to write (64 in this case)
  • The next two bytes are the start address in the EEPROM to write
  • The next 64 bytes are the data
  • The last byte is 'P' (0x50) to indicate stop

The read command is composed of these bytes:

  • The first byte is 'S' (0x53) to indicate an I2C start
  • The second byte is the EEPROM I2C address and write command (0x50 << 1 | 0 = 0xA0 )
  • The third byte is the length of the data (0x02), which is for the 2-byte address
  • The next two bytes are the start address in the EEPROM to read
  • The next byte is 'S' (0x53) to indicate an I2C restart
  • The next byte is the EEPROM I2C address and the read command (0x50<<1 | 1 = 0xA1)
  • The next byte is the length of the read data (64 bytes) (0x40)
  • The last byte is 'P' (0x50) to indicate stop

Figure 6-9 shows that the read data is the same as the write data.

GUID-37C81DB3-5B5A-45BC-B435-8447BEFA9D55-low.pngFigure 6-9 Write and Read EEPROM Value