gpio interrupt conflicts with spi
Posted: Mon Apr 24, 2017 2:53 pm
Hi everyone,
Have a good day. i am using spi and gpio interrupt for my new project. but the spi is not working when i enable the gpio interrupts. what could be the reason for this. any help would be much helpful for me.
my code :
void app_main()
{
gpio_config_t io_conf;
//configure output pins without interupt
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pin_bit_mask = (1<<SPISTE);
io_conf.pull_down_en = 0;
io_conf.pull_up_en = 0;
gpio_config(&io_conf);
io_conf.intr_type = GPIO_PIN_INTR_POSEDGE;
io_conf.pin_bit_mask = (1<<SPIDRDY);;
io_conf.mode = GPIO_MODE_INPUT;
io_conf.pull_up_en = 1;
gpio_config(&io_conf);
//gpio_set_intr_type(SPIDRDY, GPIO_INTR_POSEDGE);
gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t));
xTaskCreate(gpio_task_example, "gpio_task_example", 2048, NULL, 10, NULL);
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
gpio_isr_handler_add(SPIDRDY, gpio_isr_handler, (void*) SPIDRDY);
spi_device_handle_t spi;
esp_err_t ret;
spi_bus_config_t buscfg=
{
.miso_io_num=SOMI,
.mosi_io_num=SIMO,
.sclk_io_num=SCLK,
.quadwp_io_num=-1,
.quadhd_io_num=-1
};
spi_device_interface_config_t devcfg={
.clock_speed_hz=2000000, //Clock out at 2 MHz
.mode=0, //SPI mode 0
.spics_io_num=CS, //CS pin
.queue_size=7, //We want to be able to queue 7 transactions at a time
};
ret=spi_bus_initialize(HSPI_HOST, &buscfg, 1);
assert(ret==ESP_OK);
ret=spi_bus_add_device(HSPI_HOST, &devcfg, &spi);
assert(ret==ESP_OK);
int cnt = 0;
int level=0;
while(1) {
gpio_set_level(SPISTE, LOW);
unsigned long data_out=CONTROL0;
uint32_t data= 0x000008;
data_out=((data_out<<24) & 0xFF);
data_out=(data_out | data);
spi_transaction_t t;
memset(&t, 0, sizeof(t));
t.length=32; //Command is 8 bits
t.tx_buffer=&data_out;
t.user=(void*)0;
ret=spi_device_transmit(spi, &t); //Transmit!
assert(ret==ESP_OK);
gpio_set_level(SPISTE, HIGH);
printf("cnt: %d\n", cnt++);
vTaskDelay(100 / portTICK_RATE_MS);
//gpio_set_level(SPISTE, level);
//level=!level;
}
}
Have a good day. i am using spi and gpio interrupt for my new project. but the spi is not working when i enable the gpio interrupts. what could be the reason for this. any help would be much helpful for me.
my code :
void app_main()
{
gpio_config_t io_conf;
//configure output pins without interupt
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pin_bit_mask = (1<<SPISTE);
io_conf.pull_down_en = 0;
io_conf.pull_up_en = 0;
gpio_config(&io_conf);
io_conf.intr_type = GPIO_PIN_INTR_POSEDGE;
io_conf.pin_bit_mask = (1<<SPIDRDY);;
io_conf.mode = GPIO_MODE_INPUT;
io_conf.pull_up_en = 1;
gpio_config(&io_conf);
//gpio_set_intr_type(SPIDRDY, GPIO_INTR_POSEDGE);
gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t));
xTaskCreate(gpio_task_example, "gpio_task_example", 2048, NULL, 10, NULL);
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
gpio_isr_handler_add(SPIDRDY, gpio_isr_handler, (void*) SPIDRDY);
spi_device_handle_t spi;
esp_err_t ret;
spi_bus_config_t buscfg=
{
.miso_io_num=SOMI,
.mosi_io_num=SIMO,
.sclk_io_num=SCLK,
.quadwp_io_num=-1,
.quadhd_io_num=-1
};
spi_device_interface_config_t devcfg={
.clock_speed_hz=2000000, //Clock out at 2 MHz
.mode=0, //SPI mode 0
.spics_io_num=CS, //CS pin
.queue_size=7, //We want to be able to queue 7 transactions at a time
};
ret=spi_bus_initialize(HSPI_HOST, &buscfg, 1);
assert(ret==ESP_OK);
ret=spi_bus_add_device(HSPI_HOST, &devcfg, &spi);
assert(ret==ESP_OK);
int cnt = 0;
int level=0;
while(1) {
gpio_set_level(SPISTE, LOW);
unsigned long data_out=CONTROL0;
uint32_t data= 0x000008;
data_out=((data_out<<24) & 0xFF);
data_out=(data_out | data);
spi_transaction_t t;
memset(&t, 0, sizeof(t));
t.length=32; //Command is 8 bits
t.tx_buffer=&data_out;
t.user=(void*)0;
ret=spi_device_transmit(spi, &t); //Transmit!
assert(ret==ESP_OK);
gpio_set_level(SPISTE, HIGH);
printf("cnt: %d\n", cnt++);
vTaskDelay(100 / portTICK_RATE_MS);
//gpio_set_level(SPISTE, level);
//level=!level;
}
}