請指點一下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做主還是做從?

撰寫答案

請登錄後再發布答案,點擊登錄

發布
問題

分享
好友

手機
浏覽

掃碼手機浏覽