Last active
November 9, 2015 15:54
-
-
Save Simon-L/b6203d3c4cefa95c13ac to your computer and use it in GitHub Desktop.
ESP8266 HSPI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void ICACHE_FLASH_ATTR | |
| spi_mast_2bytes_write(uint8 spi_no,uint16 data) | |
| { | |
| uint32 regvalue; | |
| if(spi_no>1) return; //handle invalid input number | |
| while(READ_PERI_REG(SPI_CMD(spi_no))&SPI_USR); | |
| CLEAR_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_MOSI|SPI_USR_MISO); | |
| //SPI_FLASH_USER2 bit28-31 is cmd length,cmd bit length is value(0-15)+1, | |
| // bit15-0 is cmd value. | |
| WRITE_PERI_REG(SPI_USER2(spi_no), | |
| ((SPI_USR_COMMAND_BITLEN)<<SPI_USR_COMMAND_BITLEN_S)|((uint16)data)); | |
| SET_PERI_REG_MASK(SPI_CMD(spi_no), SPI_USR); | |
| while(READ_PERI_REG(SPI_CMD(spi_no))&SPI_USR); | |
| } | |
| void manage_STP16_leds(int mask) { | |
| os_printf("Pre SPI\n"); | |
| gpio_output_set(0, BIT15, BIT15, 0); | |
| hspi_dev_sel(HSPI_CS_DEV); | |
| spi_mast_2bytes_write(HSPI, mask); | |
| gpio_output_set(BIT15, 0, BIT15, 0); | |
| os_delay_us(10); | |
| gpio_output_set(0, BIT15, BIT15, 0); | |
| os_printf("Post SPI\n"); | |
| } | |
| void user_init(void) | |
| { | |
| // system_update_cpu_freq(160); | |
| uart_div_modify(0, UART_CLK_FREQ / 115200); | |
| os_printf("SDK version:%s\n", system_get_sdk_version()); | |
| gpio_output_set(0, 0, BIT13, 0); | |
| gpio_output_set(0, 0, BIT14, 0); | |
| gpio_output_set(0, 0, BIT15, 0); | |
| hspi_master_dev_init(HSPI_CS_DEV, 0, 9); | |
| SET_PERI_REG_MASK(SPI_USER(HSPI), SPI_WR_BYTE_ORDER)); | |
| .... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment