This blog post discusses connecting CYW43907 to an I2C Slave. Cypress Serial Control (CSC) is an I2C compatible serial interface in CYW43907 and supports up to 400 KHz. CSC supports only I2C master that can be used to communicate with external I2C slaves. There are two instances of CSC blocks – I2C0 and I2C1.
I2C0 – This instance of I2C supports speeds such as 10 KHz, 100 KHz, and 400 KHz speed. I2C0 supports repeated start, however, it does not support clock stretching. Physical I2C0 pins are multiplexed with other functions(which could be found in the Pin Mux Table of CYW43907) and can be used as General Purpose I/Os(GPIO) if I2C0 is not being used by the application.
I2C1 – I2C1 also supports such as 10 KHz, 100 KHz, and 400 KHz speed. It does not support Repeated start and Clock stretching. I2C1 uses fixed function pins.
A bit banging I2C driver is also supported in WICED Studio that can be used for the applications that need to support clock stretching. Only I2C0 pins can be used for the bit-banging interface.
Pin List
The I2C pins are pulled up using 4.7K resistors in CYW943907AEVAL1F EVK.(as shown in the following figure).
I2C Interface | MURATA Module Pin Name | Pin Header |
---|---|---|
I2C0_SCLK | I2C_0_SCL | J6. 23 |
I2C0_SDATA | I2C_0_SDA | J6.25 |
I2C1_SCLK | I2C_1_SCL | J12 .9 |
I2C1_SDATA | I2C_1_SDA | J12.10 |
Adding I2C to your application in WICED Studio
Wiced Studio supports GSIO (CSC) based I2C or bit-banging. The I2C bit-banging driver is more CPU Intensive than the default hardware driver, so it is recommended to use I2C bit-banging only when the slave requires clock stretching. Note that I2C1 doesn't support bit-banging and hence the following options are applicable only for I2C0 interface.
The drivers available for I2C0 could be selected in the platform file of CYW43907.(/43xxx_Wi-Fi/platforms/CYW943907AEVAL1F/platform.c)
Modify the I2C peripherals structure (platform_i2c_peripherals)
API’s available
In WICED Studio, physical I2C0 is referred as WICED_I2C_1 and I2C1 is referred as WICED_I2C_1 and must be used accordingly with APIs.
I2C API’s are defined in /43xxx_Wi-Fi/WICED/platform/MCU/wiced_platform_common.c.
API documentation included as part of WICED Studio covers these APIs in great detail, here is high-level description of APIs available for I2C for this device -
1.wiced_result_t wiced_i2c_init (const wiced_i2c_device_t * device)
Description: Initializes an I2C interface for communication as a master. The I2C port, speed modes, start address, addressing width along with the mode of operation (with or without DMA) for the interface is configured using this API. The API resets the I2C Pins to remove any previous states on the pins.
2.wiced_result_t wiced_i2c_write (const wiced_i2c_device_t* device, uint16_t flags, const void* buffer, uint16_t buffer_length )
Description: Writes data over the i2c interface. The start byte is (0000001) which pulls the SDA line low while the clock is high hence meeting the start condition. This is followed by the slave address. The data bytes are then transmitted to the slave. The stop condition is generated if the slave NACKs or the data transaction
completes through its entire length. The master sends a dummy byte before the stop condition is generated. It supports repeated start as well where the sender transfers multiple data bytes without sending the stop bit in between transfers. The Repeated start is supported only in I2C0 interface.
The flags that need to be passed to the API for generating the stop and start conditions respectively: WICED_I2C_STOP_FLAG, WICED_I2C_START_FLAG, WICED_I2C_REPEATED_START_FLAG
3.wiced_result_t wiced_i2c_read( const wiced_i2c_device_t* device, uint16_t flags, void* buffer, uint16_t buffer_length )
Description: Read data over an I2C interface from the slave corresponding to the slave address. The transaction begins with a start byte from the master, followed by slave address. Data is read from the slave. This continues till the entire length of data is read or the slave NACKs. A dummy byte is sent by the master, before generating a stop condition. The flags that need to be passed to the API for generating the stop and start conditions respectively: WICED_I2C_STOP_FLAG, WICED_I2C_START_FLAG, WICED_I2C_REPEATED_START_FLAG.
4. wiced_result_t wiced_i2c_transfer( const wiced_i2c_device_t* device, wiced_i2c_message_t* messages, uint16_t number_of_messages )
Description: Used to do read/write data over an I2C interface. It supports repeated start condition where the sender transfers multiple data bytes without sending the stop bit in between transfers. The repeated start condition can only be generated in I2C0 interface.
5. wiced_bool_t wiced_i2c_probe_device( const wiced_i2c_device_t* device, int retries )
Description: Checks whether the device is available on a bus or not. This reads 2 bytes of data from the addressed slave. The slave won’t be acknowledged if it isn’t on the I2C Bus in which case the API returns 0.
Relevant Macros and Flags:
WICED Ports
(a) WICED_I2C_1(b) WICED_I2C_2
Addressing and Speed modes
Address width available for addressing the slave is set using the following enum flags.(For both GSIO and BB Drivers).
I2C_ADDRESS_WIDTH_7BIT
I2C_ADDRESS_WIDTH_10BIT
I2C_ADDRESS_WIDTH_16BIT
Speed Modes available for the two drivers (Bit banging and GSIO) and the corresponding enum flags.
SPEED MODES | BIT BANGING | GSIO |
---|---|---|
I2C_LOW_SPEED_MODE | 5KHz | 10KHz |
I2C_STANDARD_SPEED_MODE | 50KHz | 100KHz |
I2C_HIGH_SPEED_MODE | 100KHz | 400KHz |
The application attached reads the ADC output via an I2C interface and display in a webpage. Follow the instructions added as comments in the code.
Show LessThis snippet application interfaces the FXOS8700 accelerometer and magnetometer sensors to Wiced SDK using I2C interface.
Features demonstrated
- I2C device setup and connection using WICED
- I2C device data send and receive using WICED
- Interface to I2C sensor device
Snipped application:
- Sets up the I2C interface to the device and communicates to read and write sensor registers.
- Sets up the interrupts using WICED GPIO interrupt handling function.
- Calibrates the accelerometer and magnetometer sensors in the FXOS8700.
- On each interrupt from the FXOS8700, the sensor data is read and printed on the serial terminal.
Connection setup for I2C device to STM32F4xx based WICED evaluation board
FRDM-STBC-AGM01 BCM943341WCD1 J7 Header
J3-1 + J7-28
J4-5 - J7-27
J3-5 SDA J7-26
J3-4 SCL J7-25
J4-1 INT1_8700 J7-8
J4-8 INT1_21002 J7-7
NOTE: On BCM943341WCD1, SDA and SCL signals already have a 4.7K pull up resistors.
Connect a PC terminal to the serial port of the WICED Eval board, then build and download the application as described in the WICED Quick Start Guide.
Either apply the attached patch or copy the attached files to ../apps/snip directory.
Application could be built using following Make Target command for BCM943341WCD1 platform:
snip.i2c_fxo-BCM943341WCD1 download run
snip.i2c_fxo-BCM943341WCD1-debug download run
Here is the BCM943341WCD1 EVB with FRDM-STBC-AGM01 EVB:
Here is the serial terminal output:
.
Show LessThis snippet application interfaces the Infrared contact-less temperature sensor (TMP007) module from Adafruit (https://www.adafruit.com/products/2023) using WICED SDK.
- The snippet application sets up the I2C device interface and probes the device.
- Then all register values are read and pushed to the serial terminal interface.
- To show writing to the I2C device, object high temperature alarm register is updated with a given value then the same register is register back.
- Every 1 second period, I2C device die and object temperature values are read from corresponding registers and printed on the serial terminal.
For BCM943362WCD4 evaluation platform update the platform.c and platform.h files for I2C device.
Update the .../platforms/BCM943362WCD4/platform.c file by adding the following changes to the file:
const platform_i2c_t platform_i2c_peripherals[] =
{
[WICED_I2C_1] =
{
.port = I2C1,
.pin_scl = &platform_gpio_pins[WICED_GPIO_11],
.pin_sda = &platform_gpio_pins[WICED_GPIO_12],
.peripheral_clock_reg = RCC_APB1Periph_I2C1,
.tx_dma = DMA1,
.tx_dma_peripheral_clock = RCC_AHB1Periph_DMA1,
.tx_dma_stream = DMA1_Stream7,
.rx_dma_stream = DMA1_Stream0,
.tx_dma_stream_id = 7,
.rx_dma_stream_id = 0,
.tx_dma_channel = DMA_Channel_1,
.rx_dma_channel = DMA_Channel_1,
.gpio_af = GPIO_AF_I2C1
}
};
For platforms/BCM943362WCD4/platform.h file add the WICED_I2C_1 to the wiced_i2c_t as below:
typedef enum
{
WICED_I2C_1,
WICED_I2C_MAX,
WICED_I2C_32BIT = 0x7FFFFFFF,
} wiced_i2c_t;
The platform files for BCM943362WCD4 are attached.
NOTE: On BCM943362WCD4 evaluation board, two 4.7K pull up resistors are needs on each of the SCL and SDA connections.
For BCM943341WCD1, the I2C device of WICED_I2C_1 is already defined in the platform files. Since the SCL and SDA pull resistors are already populated on the BCM943341WCD1 evaluation board, no hardware related modifications are needed.
Your application specific platform files can be updated as above to interface the chosen I2C device to the WICED SDK 3.x platforms.
1. To run the test, connect the I2C device to the evaluation board as following:
Connection setup for I2C device to STM32F4xx based WICED evaluation board
I2C-Device BCM943341WCD1 J7 Header
- J7-27
+ J7-28
SDA J7-26
SCL J7-25
Connection setup for I2C device to STM32F2xx based WICED evaluation board
I2C-Device BCM943362WCD4 J7 Header
- J7-2
+ J7-1
SDA J7-7
SCL J7-6
2. Unzip and copy the attached files to the WICED SDK-3.x version.
For I2C Temp application snippet:
Copy the content of the i2c_temp.7z source to .../apps/snip/i2c_temp
For BCM943362WCD4:
Copy the content of the BCM943362WCD4.7z source to .../platforms/BCM943362WCD4
For BCM943341WCD1:
Default platform files could be used.
3. To build, download and run the application below
For STM32F4xx MCU BCM943341WCD1:
snip.i2c_temp-BCM943341WCD1 download run
For STM32F2xx MCU BCM943362WCD4:
snip.i2c_temp-BCM943362WCD4 download run
Picture of setup:
Serial terminal log:
Show Less13:15:39.028: Starting WICED v3.3.DEVELOPMENT
13:15:39.028: Platform BCM943341WCD1 initialised
13:15:39.028: Started ThreadX v5.6
13:15:39.028: Initialising NetX_Duo v5.7_sp2
13:15:39.028: Creating Packet pools
13:15:39.028: WWD SDIO interface initialised
13:15:39.348: WLAN MAC Address : 6C:AD:F8:F0:E8:F1
13:15:39.364: WLAN Firmware : wl0: Nov 25 2015 14:01:39 version 6.49.2 (r602357) FWID 01-1302682f
13:15:39.364: I2C LED Interface Application.
13:15:39.396: Probe successful on address 64!
13:15:39.396: Manufacturer ID: 0x5449
13:15:39.396: Device ID: 0x0078
13:15:39.396: Voltage: -27.6562 uV
13:15:39.396: Die Temp: 25.22C
13:15:39.396: Object Temp: 25.12C
13:15:39.412: Alarms(L/H): Die -256.00C / 255.50C, Object -256.00C / 198.50C
13:15:39.412: Write: 6340 Read: 6340
13:15:39.412: Write: 198.50C Read: 198.50C
13:15:39.412: Die Temp: 25.22C (78.39F) - Object Temp: 25.12C (77.22F)
13:15:39.428: Die Temp: 25.19C (78.34F) - Object Temp: 25.19C (77.34F)
13:15:40.420: Die Temp: 25.19C (78.34F) - Object Temp: 25.34C (77.62F)
13:15:41.428: Die Temp: 25.19C (78.34F) - Object Temp: 26.38C (79.47F)
13:15:42.436: Die Temp: 25.19C (78.34F) - Object Temp: 28.12C (82.62F)
13:15:43.444: Die Temp: 25.19C (78.34F) - Object Temp: 30.03C (86.06F)
13:15:44.451: Die Temp: 25.22C (78.39F) - Object Temp: 32.50C (90.50F)
13:15:45.459: Die Temp: 25.22C (78.39F) - Object Temp: 34.25C (93.65F)
13:15:46.451: Die Temp: 25.22C (78.39F) - Object Temp: 33.12C (91.62F)
13:15:47.460: Die Temp: 25.22C (78.39F) - Object Temp: 32.47C (90.44F)
13:15:48.468: Die Temp: 25.22C (78.39F) - Object Temp: 33.06C (91.51F)
13:15:49.476: Die Temp: 25.22C (78.39F) - Object Temp: 33.91C (93.03F)
13:15:50.484: Die Temp: 25.22C (78.39F) - Object Temp: 34.59C (94.27F)
13:15:51.476: Die Temp: 25.22C (78.39F) - Object Temp: 34.97C (94.94F)
13:15:52.484: Die Temp: 25.25C (78.45F) - Object Temp: 35.38C (95.68F)
13:15:53.492: Die Temp: 25.25C (78.45F) - Object Temp: 35.06C (95.11F)
13:15:54.500: Die Temp: 25.25C (78.45F) - Object Temp: 33.53C (92.36F)
13:15:55.507: Die Temp: 25.22C (78.39F) - Object Temp: 32.19C (89.94F)
13:15:56.515: Die Temp: 25.22C (78.39F) - Object Temp: 30.94C (87.69F)
13:15:57.508: Die Temp: 25.22C (78.39F) - Object Temp: 31.34C (88.42F)
13:15:58.516: Die Temp: 25.28C (78.51F) - Object Temp: 34.59C (94.27F)
13:15:59.524: Die Temp: 25.34C (78.62F) - Object Temp: 38.72C (101.69F)
13:16:00.532: Die Temp: 25.38C (78.68F) - Object Temp: 41.81C (107.26F)
13:16:01.540: Die Temp: 25.44C (78.79F) - Object Temp: 44.59C (112.27F)
13:16:02.532: Die Temp: 25.50C (78.90F) - Object Temp: 47.03C (116.66F)
13:16:03.540: Die Temp: 25.53C (78.96F) - Object Temp: 48.81C (119.86F)
13:16:04.548: Die Temp: 25.59C (79.07F) - Object Temp: 49.91C (121.83F)
13:16:05.556: Die Temp: 25.62C (79.12F) - Object Temp: 50.91C (123.63F)
13:16:06.563: Die Temp: 25.66C (79.18F) - Object Temp: 51.44C (124.59F)
13:16:07.557: Die Temp: 25.72C (79.29F) - Object Temp: 52.41C (126.33F)
13:16:08.564: Die Temp: 25.75C (79.35F) - Object Temp: 52.94C (127.29F)
13:16:09.572: Die Temp: 25.81C (79.46F) - Object Temp: 54.03C (129.26F)
13:16:10.580: Die Temp: 25.88C (79.58F) - Object Temp: 54.62C (130.32F)
13:16:11.588: Die Temp: 25.91C (79.63F) - Object Temp: 55.19C (131.34F)
13:16:12.596: Die Temp: 25.94C (79.69F) - Object Temp: 55.84C (132.52F)
13:16:13.588: Die Temp: 26.00C (79.80F) - Object Temp: 56.59C (133.87F)
13:16:14.596: Die Temp: 26.06C (79.91F) - Object Temp: 57.34C (135.22F)
13:16:15.604: Die Temp: 26.09C (79.97F) - Object Temp: 58.06C (136.51F)
13:16:16.612: Die Temp: 26.16C (80.08F) - Object Temp: 58.78C (137.81F)
13:16:17.621: Die Temp: 26.22C (80.19F) - Object Temp: 59.47C (139.04F)
13:16:18.613: Die Temp: 26.28C (80.31F) - Object Temp: 60.03C (140.06F)
13:16:19.620: Die Temp: 26.34C (80.42F) - Object Temp: 60.38C (140.68F)
13:16:20.628: Die Temp: 26.41C (80.53F) - Object Temp: 60.84C (141.52F)
13:16:21.636: Die Temp: 26.50C (80.70F) - Object Temp: 60.62C (141.12F)
13:16:22.644: Die Temp: 26.59C (80.87F) - Object Temp: 60.34C (140.62F)
13:16:23.653: Die Temp: 26.69C (81.04F) - Object Temp: 60.22C (140.39F)
13:16:24.644: Die Temp: 26.75C (81.15F) - Object Temp: 60.56C (141.01F)
13:16:25.652: Die Temp: 26.81C (81.26F) - Object Temp: 58.62C (137.53F)
13:16:26.660: Die Temp: 26.78C (81.21F) - Object Temp: 53.47C (128.24F)
13:16:27.669: Die Temp: 26.78C (81.21F) - Object Temp: 48.19C (118.74F)
13:16:28.677: Die Temp: 26.81C (81.26F) - Object Temp: 44.44C (111.99F)
13:16:29.669: Die Temp: 26.81C (81.26F) - Object Temp: 41.47C (106.64F)
13:16:30.677: Die Temp: 26.81C (81.26F) - Object Temp: 39.09C (102.37F)
13:16:31.684: Die Temp: 26.84C (81.32F) - Object Temp: 37.34C (99.22F)
13:16:32.692: Die Temp: 26.84C (81.32F) - Object Temp: 36.00C (96.80F)
13:16:33.700: Die Temp: 26.84C (81.32F) - Object Temp: 34.84C (94.72F)
13:16:34.692: Die Temp: 26.84C (81.32F) - Object Temp: 34.00C (93.20F)
13:16:35.700: Die Temp: 26.84C (81.32F) - Object Temp: 33.25C (91.85F)
13:16:36.708: Die Temp: 26.84C (81.32F) - Object Temp: 32.84C (91.12F)
13:16:37.717: Die Temp: 26.84C (81.32F) - Object Temp: 32.59C (90.67F)
This application snippet demonstrates the I2C device interface using WICED SDK-3.x.
The sample application sets up the I2C device interface and send commands to the I2C device then receives replies, if any, from the I2C device.
For this example "BlinkM - I2C Controlled RGB LED" (www.sparkfun.com/products/8579) I2C device is used to test the code. It could be any other I2C device chosen for your platform as well.
For BCM943362WCD4 evaluation platform update the platform.c and platform.h files for I2C device.
Update the .../platforms/BCM943362WCD4/platform.c file by adding the following changes to the file:
const platform_i2c_t platform_i2c_peripherals[] =
{
[WICED_I2C_1] =
{
.port = I2C1,
.pin_scl = &platform_gpio_pins[WICED_GPIO_11],
.pin_sda = &platform_gpio_pins[WICED_GPIO_12],
.peripheral_clock_reg = RCC_APB1Periph_I2C1,
.tx_dma = DMA1,
.tx_dma_peripheral_clock = RCC_AHB1Periph_DMA1,
.tx_dma_stream = DMA1_Stream7,
.rx_dma_stream = DMA1_Stream0,
.tx_dma_stream_id = 7,
.rx_dma_stream_id = 0,
.tx_dma_channel = DMA_Channel_1,
.rx_dma_channel = DMA_Channel_1,
.gpio_af = GPIO_AF_I2C1
}
};
For platforms/BCM943362WCD4/platform.h file add the WICED_I2C_1 to the wiced_i2c_t as below:
typedef enum
{
WICED_I2C_1,
WICED_I2C_MAX,
WICED_I2C_32BIT = 0x7FFFFFFF,
} wiced_i2c_t;
The platform files for BCM943362WCD4 are attached.
For BCM943341WCD1 I2C device of WICED_I2C_1 is already defined in the platform files. For completeness the platform files are attached. The I2C device of WICED_I2C_1 for BCM943362WCD1 is already defined in the platform files. For completeness the platform files are attached.
Your application specific platform files can be updated as above to interface the chosen I2C device to the WICED SDK 3.x platform.
1. To run the test, connect the I2C device to the evaluation board as following:
Connection setup for I2C device to STM32F4xx based WICED evaluation board
I2C-Device BCM943341WCD1 J7 Header
- J7-27
+ J7-28
SDA J7-26
SCL J7-25
Connection setup for I2C device to STM32F2xx based WICED evaluation board
I2C-Device BCM943362WCD4 J7 Header
- J7-2
+ J7-1
SDA J7-7
SCL J7-6
2. Unzip and copy the attached files to the WICED SDK-3.x version.
For I2C LED application snippet:
Copy the content of the i2c_led.7z source to .../apps/snip/i2c_led
For BCM943362WCD4:
Copy the content of the BCM943362WCD4.7z source to .../platforms/BCM943362WCD4
For BCM943341WCD1:
Copy the content of the BCM943341WCD1.7z source to .../platforms/BCM943341WCD1
3. To build, download and run the application below
For STM32F4xx MCU BCM943341WCD1:
snip.i2c_led-BCM943341WCD1-debug download run
For STM32F2xx MCU BCM943362WCD4:
snip.i2c_led-BCM943362WCD4-debug download run
This is the modified STM32F4xx MCU BCM943341WCD1 WICED evaluation board:
NOTE: There are no hardware nor platform file changes needed on the BCM943341WCD1 evaluation because the already defined I2C lines ,with pull-up resistors, are used.
This is the modified STM32F2xx MCU BCM943362WCD4 Wiced evaluation board:
NOTE: On BCM943362WCD4 evaluation board, SDA and SCL signals needs 4.7K pull up resistors.
Show Less