UART, I2C, SPI Communication via Infineon PSoC™6

Communication Protocols UART/I2C/SPI

UART (Universal Asynchronous Receiver-Transmitter)

Purpose: Communication between devices.

How it works: Sends data one bit at a time, in sequence.

Key Features:

  • Only 2 wires are needed: Transmit (TX) and Receive (RX).

  • No clock signal (it's asynchronous).

  • Devices need to agree on a data rate (baud rate) beforehand.

Analogy: Think of UART like two people talking on walkie-talkies. One person speaks (transmits), and the other listens (receives), and vice versa. Both people need to agree on the speed of their conversation (like speaking slowly) to understand each other.

Printing with retarget io using UART

To use the retarget-io library to print messages, you can follow these steps:

  1. Add the Library: Utilize the Library Manager to incorporate the retarget-io library to your project. You can find this library under the "Peripherals" category.

  2. Include the Header File: In your main.c file, include the header file for the library by adding the line #include "cy_retarget_io.h" at the beginning of your file.

  3. Initialize the Interface: In the initialization segment of your firmware, call the function cy_retarget_io_init to initialize the communication interface. This function utilizes the PSoC™ debug UART pins that are connected to KitProg3, and it initializes the interface with a default baud rate of 115200. Here is how you can call this function:

  4. Using printf: Now, you can use the printf function in your code just like you normally would. For instance, to print a variable named "myVar", you can use a line of code like this:

    printf("The value of myVar is: %d\n", myVar);

I2C (Inter-Integrated Circuit)

Purpose: Communication between devices, often within the same circuit board.

How it works: Multiple devices can be connected in a 'bus' system using only 2 wires.

Key Features:

  • 2 wires: Serial Data (SDA) and Serial Clock (SCL).

  • Devices have unique addresses so they can be individually spoken to.

  • One master device controls the communication; others are slaves.

Analogy: Think of I2C like a teacher (master) in a classroom, and the students (slaves) are the devices. The teacher asks a specific student a question by calling their name (address) and waits for an answer.

To facilitate communication between a master device and a slave device, there are several functions available for reading and writing data. Here’s a brief overview:

Master and Slave Communication Using I2C Functions in Infineon

Master-Side Functions

  1. Dedicated Read and Write Functions:

    • cyhal_i2c_master_read: A dedicated function to perform read operations from the slave.

    • cyhal_i2c_master_write: A dedicated function to perform write operations to the slave.

  2. Memory-Specific Read and Write Functions:

    • cyhal_i2c_master_mem_read: This function allows the master to read a block of data from a specified memory address in the slave.

    • cyhal_i2c_master_mem_write: This function enables the master to write a block of data to a specific memory address in the slave.

  3. Asynchronous Transfer Function:

    • cyhal_i2c_master_transfer_async: A versatile function that can perform either read, write, or both operations asynchronously.

Slave-Side Functions

To configure the read and write buffers of the slave, the following functions are available:

  • cyhal_i2c_slave_config_read_buffer: A function to configure the slave's read buffer.

  • cyhal_i2c_slave_config_write_buffer: A function to configure the slave's write buffer.

Documentation and Resources

For more detailed information and usage examples, you can refer to the documentation for the HAL I2C functions, which can be found in the following section of the official documentation:

  • Hardware Abstraction Layer (HAL): Hardware Abstraction Layer > HAL API Reference > HAL Drivers > I2C.

SPI (Serial Peripheral Interface)

Purpose: Fast communication between devices.

How it works: Sends data simultaneously in both directions.

Key Features:

  • More than 2 wires: at least 4 (Master Out Slave In, Master In Slave Out, Clock, and Chip Select).

  • One master, multiple slaves.

  • It's synchronous (uses a clock).

Analogy: Imagine a conveyor belt (SPI) with people on either side passing boxes (data) back and forth. There's a rhythm or clock to when they pass and receive boxes, making the transfer efficient.

Last updated

Assoc. Prof. Wiroon Sriborrirux, Founder of Advance Innovation Center (AIC) and Bangsaen Design House (BDH), Electrical Engineering Department, Faculty of Engineering, Burapha University