请指点一下 W801 低速 SPI 从设备的使用方法, W801 与 W5500 无法收发数据.

发布于 2024-07-09 13: 47: 20

include "wm_include. h"

include "bsp_flash. h"

include "wm_gpio_afsel. h"

void UserMain (void)
{

uint8_t key=0; 
IINCHIP_WRITE ( 0x000000,   0x01) ; //00000101
printf ("接收:  %X",  IINCHIP_READ (0x000000) ) ;     

}

include "string. h"

include "wm_include. h"

include "wm_demo. h"

include "wm_hostspi. h"

include "wm_gpio_afsel. h"

include "wm_gpio. h"

include "bsp_flash. h"

define SPI_DATA_LEN 4

define SPI_CLOCK 1000000 // 1 MHz

uint8_t SPI_FLASH_SendByte (uint8_t byte)
//master_spi_send_data (int clk, int type)
{

uint8_t rec = 0; 
wm_spi_ck_config (WM_IO_PB_15) ; 
wm_spi_di_config (WM_IO_PB_16) ; 
wm_spi_do_config (WM_IO_PB_17) ; 
tls_gpio_cfg (WM_IO_PB_14,  WM_GPIO_DIR_OUTPUT,  WM_GPIO_ATTR_PULLHIGH) ; /* cs */
tls_spi_init () ; 
tls_spi_trans_type (SPI_DMA_TRANSFER) ; 
tls_spi_setup (TLS_SPI_MODE_3,  TLS_SPI_CS_LOW,  TLS_SPI_FCLK_MAX) ; 
tls_gpio_write (WM_IO_PB_14,  0) ; 
tls_spi_write (&byte,  1) ; 
tls_spi_read (&rec,  1) ; 
tls_gpio_write (WM_IO_PB_14,  1) ; 
return rec; 

}

uint8_t SPI_FLASH_ReadByte (void) {

return SPI_FLASH_SendByte (0xFF) ; 

}
/**
*@brief 从 w5500 读出一个 8 位数据
*@param addrbsb: 写入数据的地址
*@param data: 从写入的地址处读取到的数据
*@return 无
*/

uint8_t IINCHIP_READ (uint32 addrbsb)
{

uint8_t data = 0; 
tls_gpio_write (WM_IO_PB_14,  0) ;                           
IINCHIP_SpiSendData (  (addrbsb & 0x00FF0000) " " 16) ; 
IINCHIP_SpiSendData (  (addrbsb & 0x0000FF00) " "  8) ; 
IINCHIP_SpiSendData (  (addrbsb & 0x000000F8) )     ; 
data = IINCHIP_SpiSendData (0x00) ;             
tls_gpio_write (WM_IO_PB_14,  1) ;                               
return data;     

}

/**
*@brief 写入一个 8 位数据到 W5500
*@param addrbsb: 写入数据的地址
*@param data; 写入的 8 位数据
*@return 无
*/
void IINCHIP_WRITE ( uint32 addrbsb, uint8_t data)
{

tls_gpio_write (WM_IO_PB_14,  0) ;                                      
IINCHIP_SpiSendData (  (addrbsb & 0x00FF0000) " " 16) ;     
IINCHIP_SpiSendData (  (addrbsb & 0x0000FF00) " "  8) ; 
IINCHIP_SpiSendData (  (addrbsb & 0x000000F8)  + 4) ;   
IINCHIP_SpiSendData (data) ;      

tls_gpio_write (WM_IO_PB_14, 1) ;
}

/**
*@brief W800 SPI 读写 8 位数据
*@param dat 写入的 8 位数据
*@return 无
*/
uint8_t IINCHIP_SpiSendData (uint8_t dat)
{

return (SPI_FLASH_SendByte (dat) ) ; 

}

查看更多

关注者
0
被浏览
1. 3k
1 个回答
abcd
abcd 认证专家 2024-07-09
我只是个路过的老年人~

w800 做主还是做从?

撰写答案

请登录后再发布答案, 点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览