- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I followed the example : 20719-B1_Bluetooth\apps\snip\hal\spi_master to create a SPI communication with a 3-axis g-sensor. But I found the SPI_CS will back to inactive too early that will cause an incorrect Writing operation. .
I also used PSOC6 to do the same thing, and PSOC6 did very well:
These r the codes:
void init_spi()
{
wiced_hal_pspi_init(SPI_MASTER, INPUT_PIN_PULL_DOWN, MASTER_P38_CLK_P28_MOSI_P01_MISO, DEFAULT_FREQUENCY, SPI_MSB_FIRST, SPI_SS_ACTIVE_LOW, SPI_MODE_3, SPI_CS);
}
void send_data(unsigned char register_address, unsigned char *value, unsigned char number_of_bytes)
{
unsigned char send_data[2];
unsigned char rec_data[8];
if( 1!= number_of_bytes )
{
WICED_BT_TRACE("mcube_read_regs bytes error =%d\r\n", number_of_bytes);
}
WICED_BT_TRACE("WR: reg = 0x%02x, value = 0x%02x\r\n", register_address, *value);
send_data[0] = register_address |0x40; // 1 bytes; write operation
send_data[1] = *value;
wiced_hal_pspi_exchange_data(sizeof(send_data), send_data, rec_data);
}
Another question is, Since the SPI_CS is controlled by SPI driver automatically, why the sample code write there red codes?
....
wiced_hal_gpio_configure_pin(CS, GPIO_OUTPUT_ENABLE, GPIO_PIN_OUTPUT_HIGH);
wiced_hal_pspi_init(SPI_MASTER, INPUT_PIN_PULL_UP, MASTER_P38_CLK_P28_MOSI_P01_MISO, DEFAULT_FREQUENCY, SPI_LSB_FIRST, SPI_SS_ACTIVE_LOW, SPI_MODE_0, CS);
....
wiced_hal_gpio_set_pin_output(CS, GPIO_PIN_OUTPUT_LOW);
wiced_hal_pspi_tx_data(sizeof(start_byte), &start_byte);
wiced_hal_gpio_set_pin_output(CS, GPIO_PIN_OUTPUT_HIGH);
.....
wiced_rtos_delay_milliseconds(20, 1);
wiced_hal_gpio_set_pin_output(CS, GPIO_PIN_OUTPUT_LOW);
wiced_hal_pspi_rx_data(sizeof(rec_byte), rec_byte);
wiced_hal_gpio_set_pin_output(CS, GPIO_PIN_OUTPUT_HIGH);
....
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This was an internal API. WICED 6.2 has replaced this API with wiced_hal_i2c_combined_read. Update your WICED to the latest version and you will be able to see this new API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
The cs pin is controlled as GPIO, you can just try to add some delay before you set the cs pin to high state.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi zhxh,
CS is not a GPIO,
1. After the PIN configured to SPI_CS, the CS cannot be controlled by wiced_hal_gpio_set_pin_output(CS, GPIO_PIN_OUTPUT_LOW);
const wiced_platform_gpio_t platform_gpio_pins[] =
{
[PLATFORM_GPIO_0 ] = {WICED_P00, WICED_GPIO }, //Button
[PLATFORM_GPIO_1 ] = {WICED_P01, WICED_SPI_1_MISO },
[PLATFORM_GPIO_2 ] = {WICED_P02, WICED_PCM_OUT_I2S_DO },
[PLATFORM_GPIO_3 ] = {WICED_P04, WICED_PCM_IN_I2S_DI },
[PLATFORM_GPIO_4 ] = {WICED_P06, WICED_GPIO },
[PLATFORM_GPIO_5 ] = {WICED_P07, WICED_SPI_1_CS },
.....
wiced_hal_pspi_init(SPI_MASTER, INPUT_PIN_PULL_DOWN, MASTER_P38_CLK_P28_MOSI_P01_MISO, DEFAULT_FREQUENCY, SPI_MSB_FIRST, SPI_SS_ACTIVE_LOW, SPI_MODE_3, SPI_CS);
MUST:
wiced_hal_gpio_select_function(SPI_CS, WICED_GPIO),
wiced_hal_gpio_configure_pin(SPI_CS, GPIO_OUTPUT_ENABLE, GPIO_PIN_OUTPUT_HIGH);
then you can set pin (SPI_CS).
2. The SPI_CS will go HIGH /LOW automatically while writing or reading operation even if you comment out these code:
wiced_hal_gpio_configure_pin(SPI_CS, GPIO_OUTPUT_ENABLE, GPIO_PIN_OUTPUT_HIGH);
wiced_hal_gpio_set_pin_output(CS, GPIO_PIN_OUTPUT_LOW);
wiced_hal_gpio_set_pin_output(CS, GPIO_PIN_OUTPUT_HIGH);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
You need to edit the /20719-B1_Bluetooth/platforms/CYW920719Q40EVB_01/wiced_platform_pin_config.c file as follows (Highlighted text)
Current code:
const wiced_platform_gpio_t platform_gpio_pins[] =
{
[PLATFORM_GPIO_0 ] = {WICED_P00, WICED_GPIO }, //Button
[PLATFORM_GPIO_1 ] = {WICED_P01, WICED_SPI_1_MISO },
[PLATFORM_GPIO_2 ] = {WICED_P02, WICED_PCM_OUT_I2S_DO },
[PLATFORM_GPIO_3 ] = {WICED_P04, WICED_PCM_IN_I2S_DI },
[PLATFORM_GPIO_4 ] = {WICED_P06, WICED_GCI_GPIO_06 },
[PLATFORM_GPIO_5 ] = {WICED_P07, WICED_SPI_1_CS },
[PLATFORM_GPIO_6 ] = {WICED_P10, WICED_GCI_GPIO_07 },
[PLATFORM_GPIO_7 ] = {WICED_P16, WICED_PCM_CLK_I2S_CLK },
[PLATFORM_GPIO_8 ] = {WICED_P17, WICED_PCM_SYNC_I2S_WS },
[PLATFORM_GPIO_9 ] = {WICED_P26, WICED_GPIO }, //Default LED 2
[PLATFORM_GPIO_10] = {WICED_P25, WICED_I2C_1_SCL },
[PLATFORM_GPIO_11] = {WICED_P28, WICED_SPI_1_MOSI }, //Optional LED 1
[PLATFORM_GPIO_12] = {WICED_P29, WICED_I2C_1_SDA },
[PLATFORM_GPIO_13] = {WICED_P33, WICED_UART_2_TXD },
[PLATFORM_GPIO_14] = {WICED_P34, WICED_UART_2_RXD },
[PLATFORM_GPIO_15] = {WICED_P38, WICED_SPI_1_CLK },
};
New Code:
const wiced_platform_gpio_t platform_gpio_pins[] =
{
[PLATFORM_GPIO_0 ] = {WICED_P00, WICED_GPIO }, //Button
[PLATFORM_GPIO_1 ] = {WICED_P01, WICED_SPI_1_MISO },
[PLATFORM_GPIO_2 ] = {WICED_P02, WICED_PCM_OUT_I2S_DO },
[PLATFORM_GPIO_3 ] = {WICED_P04, WICED_PCM_IN_I2S_DI },
[PLATFORM_GPIO_4 ] = {WICED_P06, WICED_GCI_GPIO_06 },
[PLATFORM_GPIO_5 ] = {WICED_P07, WICED_GPIO },
[PLATFORM_GPIO_6 ] = {WICED_P10, WICED_GCI_GPIO_07 },
[PLATFORM_GPIO_7 ] = {WICED_P16, WICED_PCM_CLK_I2S_CLK },
[PLATFORM_GPIO_8 ] = {WICED_P17, WICED_PCM_SYNC_I2S_WS },
[PLATFORM_GPIO_9 ] = {WICED_P26, WICED_GPIO }, //Default LED 2
[PLATFORM_GPIO_10] = {WICED_P25, WICED_I2C_1_SCL },
[PLATFORM_GPIO_11] = {WICED_P28, WICED_SPI_1_MOSI }, //Optional LED 1
[PLATFORM_GPIO_12] = {WICED_P29, WICED_I2C_1_SDA },
[PLATFORM_GPIO_13] = {WICED_P33, WICED_UART_2_TXD },
[PLATFORM_GPIO_14] = {WICED_P34, WICED_UART_2_RXD },
[PLATFORM_GPIO_15] = {WICED_P38, WICED_SPI_1_CLK },
};
Then you can control the CS pin in your application.
This configuration should be used while using SPI as a master. When using SPI as a slave the CS pin should be connected to the SPI block (like in the default code)
Thanks
Abhishek
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi amka,
Yes, I can change SPI_CS to GPIO use gpio_select_function, config_pin, and then set_ouput also .
But writing operation still not work as expected.
I have to set pins(MOSI/MISO/CLK/CS) to GPIO_SIMULATOR while writing, and it works!.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
May I ask I2C question here ?
in the sample code, I2C_MASTER.c :
i2cm_init();
if((i2cm_comboRead((UINT8 *)&data, sizeof(UINT8), ®_add, sizeof(UINT8), LSM9DS1_ACC_GYRO_I2C_ADDRESS)))
I cannot find these two functions Definition or Prototype. But it can compile and running well.
My question is , how to write ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This was an internal API. WICED 6.2 has replaced this API with wiced_hal_i2c_combined_read. Update your WICED to the latest version and you will be able to see this new API