-->
Page 1 of 1

GPIO overlaps HSPI

PostPosted: Wed Mar 30, 2016 3:54 pm
by someother
Hello!

I'm using the MetalPhreak's (H)SPI library for ESP8266 and it looks good.

Since I need to send commands to another device (nRF24L01), I have something like this:

Code: Select alluint8_t ICACHE_FLASH_ATTR nRF24_RWReg(uint8_t reg, uint8_t value) {
   CSN_L();
   uint8_t statusreg = spi_transaction( HSPI, 8, reg, 0, 0, 8, value, 0, 0 );
   //CSN_H();
   gpio_output_set(BIT4, 0, BIT4, 0);
   return statusreg;
}


The problem is that the GPIO port overlaps the SPI ports and destroys the timing. Please see the attached image.

Any ideas? If I repeat several times CSN_L() for example, right before CSN_H, it gives some delay for the CSN IO pin, but it is awful solution.

Re: GPIO overlaps HSPI

PostPosted: Thu Mar 31, 2016 2:27 am
by someother
I don't know why my attached image is missing.

However, if you look at the SPI driver code you'll notice that it returns immediately after the data registers are loaded. Therefore the function returns before all the data is sent over the SPI bus.
[SOLUTION]: Just check if the SPI is busy and then continue:
Code: Select all   while( spi_busy( HSPI ) );
   CSN_H();