HSPI CLK管脚电压低

zsf518
Posts: 31
Joined: Thu Jul 30, 2015 3:24 pm

HSPI CLK管脚电压低

Postby zsf518 » Thu Nov 05, 2015 2:39 pm

hi,
将ESP-12 的HSPI配置为master模式,下面是初始化代码。
void ICACHE_FLASH_ATTR
spi_master_init(uint8 spi_no)
{
uint32 regvalue;

if(spi_no>1)
return; //handle invalid input number

printf("xxxxxx spi_no= %d \n", spi_no);


if(spi_no==SPI)
{
WRITE_PERI_REG(PERIPHS_IO_MUX, 0x005);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_CLK_U, 1);//configure io to spi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_CMD_U, 1);//configure io to spi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_DATA0_U, 1);//configure io to spi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_DATA1_U, 1);//configure io to spi mode
}
else if(spi_no==HSPI)
{
//WRITE_PERI_REG(PERIPHS_IO_MUX, 0x105);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, 2);//configure io to spi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, 2);//configure io to spi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, 2);//configure io to spi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, 2);//configure io to spi mode

}

printf("11111\n");

SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_CS_SETUP|SPI_CS_HOLD|SPI_USR_COMMAND|SPI_USR_MOSI);
CLEAR_PERI_REG_MASK(SPI_USER(spi_no), SPI_FLASH_MODE);
printf("2222\n");
//clear Daul or Quad lines transmission mode
CLEAR_PERI_REG_MASK(SPI_CTRL(spi_no), SPI_QIO_MODE|SPI_DIO_MODE|SPI_DOUT_MODE|SPI_QOUT_MODE);
printf("3333\n");
WRITE_PERI_REG(SPI_CLOCK(spi_no),
((39 & SPI_CLKDIV_PRE) << SPI_CLKDIV_PRE_S) |
((3&SPI_CLKCNT_N)<<SPI_CLKCNT_N_S)|
((1&SPI_CLKCNT_H)<<SPI_CLKCNT_H_S)|
((3&SPI_CLKCNT_L)<<SPI_CLKCNT_L_S)); //clear bit 31,set SPI clock div

printf("4444\n");
//set 8bit output buffer length, the buffer is the low 8bit of register"SPI_FLASH_C0"
//WRITE_PERI_REG(SPI_USER1(spi_no),
// ((7&SPI_USR_MOSI_BITLEN)<<SPI_USR_MOSI_BITLEN_S)|
// ((7&SPI_USR_MISO_BITLEN)<<SPI_USR_MISO_BITLEN_S));
}

测试HSPI 的clk管脚输出大约1.5V左右的波形,导致slaver接收失败。


原来的配置里面有一行:WRITE_PERI_REG(PERIPHS_IO_MUX, 0x105); 不知道是做什么的。
如果不屏蔽这一行,程序执行到这里后会立即卡住,导致ESP-12模块的WIFI驱动加载出现问题,ESP-12模块就会超时重启。


请帮忙解答一下。

zsf518
Posts: 31
Joined: Thu Jul 30, 2015 3:24 pm

Re: HSPI CLK管脚电压低

Postby zsf518 » Fri Nov 06, 2015 1:47 pm

我自己来解答一下吧:问题出在 WRITE_PERI_REG(PERIPHS_IO_MUX, 0x105);
改成 WRITE_PERI_REG(PERIPHS_IO_MUX, 0x005); 电平就正常了。
原因未知。

另外:这个论坛的版猪们响应速度太慢!令人难以忍受!

ESP_Faye
Posts: 1592
Joined: Mon Oct 27, 2014 11:08 am

Re: HSPI CLK管脚电压低

Postby ESP_Faye » Mon Nov 09, 2015 2:56 pm

您好,

WRITE_PERI_REG(PERIPHS_IO_MUX, 0x105);
WRITE_PERI_REG(PERIPHS_IO_MUX, 0x005);
这两句只在配置 SPI80M 时钟时使用。

您使用多少的时钟频率?如果不是 SPI80M,请将这两句删掉。

foxxml
Posts: 3
Joined: Sat May 14, 2016 11:57 pm

Re: HSPI CLK管脚电压低

Postby foxxml » Tue Jun 07, 2016 4:06 pm

I have the same problem! I use the spi sample code downloaded here: viewtopic.php?f=31&t=1346

this is what i got:
Image

yellow line is SPI_SCLK, blue line is MOSI (i changed to spi clk to 625khz)

when i zoom into the "mass" of the yellow line:
Image
the freq is happened to match the core clk(80MHZ)

No doubt, with this clock waveform, the slave device won't work!

Lucky for me, i found here. It notify that the clk pin is only 1.5 vol,
and in my case the RMS of clk pin is 1.57v.

I then add this line to my code:
WRITE_PERI_REG(PERIPHS_IO_MUX, 0x005);
IT WORKS!

I read out the original PERIPHS_IO_MUX register:
it is : 0x205.
however I can't find a detail description of this register, especially bit above 7.

can @Espressif_Faye give us a description about this ? does it have any side effect?
we're doing some serious RD on 8266, using unknown code is dangerous!


------------------------

Code: Select all

void user_init(void)
{
    os_printf("SDK version:%s\n", system_get_sdk_version());

   os_printf("------------------start------------------\n\r");

   set_data();   
   spi_master_init(HSPI);
   spi_mast_byte_write(HSPI,0xAA);

   GPIO_OUTPUT_SET(GPIO_ID_PIN(5), 1);
   
   //spi_byte_write_espslave(HSPI,0xAA);

   //spi_WR_espslave(HSPI);
   
   //spi_WR_espslave(HSPI);
   
      
   os_printf("------------------done!------------------\n\r");
   os_printf("\n\r");
   os_printf("\n\r");


   
   
}
   




Code: Select all

void ICACHE_FLASH_ATTR
    spi_master_init(uint8 spi_no)
{
   uint32 regvalue;

   if(spi_no>1) {   

      os_printf("invalid spi number!\n\r");

      return;

   } //handle invalid input number
    else if(spi_no==SPI){
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_CLK_U, 1);//configure io to spi mode
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_CMD_U, 1);//configure io to spi mode   
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_DATA0_U, 1);//configure io to spi mode   
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_DATA1_U, 1);//configure io to spi mode   
    }else if(spi_no==HSPI){
       os_printf("spi_clk HSPI %08x\r\n",READ_PERI_REG(PERIPHS_IO_MUX));
       //WRITE_PERI_REG(PERIPHS_IO_MUX, 0x001);
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, 2);//configure io to Hspi mode
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, 2);//configure io to Hspi mode   
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, 2);//configure io to Hspi mode   
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, 2);//configure io to Hspi mode   
    }

   
   //SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_CS_SETUP|SPI_CS_HOLD);
   //CLEAR_PERI_REG_MASK(SPI_USER(spi_no), SPI_FLASH_MODE|SPI_USR_COMMAND);

   SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_CS_SETUP|SPI_CS_HOLD|SPI_USR_COMMAND);
   CLEAR_PERI_REG_MASK(SPI_USER(spi_no), SPI_FLASH_MODE);

   WRITE_PERI_REG(SPI_CLOCK(spi_no),
               ((1&SPI_CLKDIV_PRE)<<SPI_CLKDIV_PRE_S)|
               ((63&SPI_CLKCNT_N)<<SPI_CLKCNT_N_S)|
               ((31&SPI_CLKCNT_H)<<SPI_CLKCNT_H_S)|
               ((63&SPI_CLKCNT_L)<<SPI_CLKCNT_L_S)); //clear bit 31,set SPI clock div
               
   os_printf("spi_clk HSPI %08x\r\n",READ_PERI_REG(SPI_CLOCK(spi_no)));



   //WRITE_PERI_REG(PERIPHS_IO_MUX_MTDO_U, READ_PERI_REG(PERIPHS_IO_MUX_MTDO_U) & 0x7F);

   os_printf("spi_clk SPI %08x\r\n",READ_PERI_REG(SPI_CLOCK(SPI)));
   os_printf("MTMO %08x\r\n", READ_PERI_REG(PERIPHS_IO_MUX_MTDO_U));

Who is online

Users browsing this forum: No registered users and 7 guests