CC2652RB硬件SPI驱动W5100S网卡进行回环测试
1. W5100S
1.1 簡介
W5100S 是一款多功能的單芯片網絡接口芯片,內部集成全硬件的TCP/IP協議棧,以太網MAC和 10Base-T/100Base-TX以太網控制器。主要應用于高集成、高穩定、高性能和低成本的嵌入式系統中。 使用W5100S,用戶MCU可以方便的處理IPv4,TCP,UDP,ICMP,IGMP,ARP,PPPoE等各種TCP/IP協議。W5100S分別擁有8KB的發送緩存和接收緩存,可以最大限度地減少MCU的開銷。 主機還可以同時使用W5100S的4個獨立的硬件SOCKETs,并基于每個硬件SOCKET開發獨立的互聯網應用。
W5100S支持SPI接口和并行系統總線接口。 它還提供低功耗/低熱量設計,WOL(Wake On LAN),以太網PHY掉電模式等。
W5100S是基于W5100改進的低成本網絡接口芯片。W5100使用的任何固件及程序都可以直接在W5100S上使用,無需任何修改。 此外,W5100S采用48引腳LQFP和QFN無鉛封裝,明顯小于W5100的80引腳封裝,方便產品小型化
1.2 W5100S與W5100、W5500的區別
| 內部架構 | 全硬件TCP / IP協議棧+ MAC + PHY | 全硬件TCP / IP協議棧+ MAC + PHY | 全硬件TCP / IP協議棧+ MAC + PHY |
| 交互接口 | SPI | SPI,8bit bus | SPI,間接總線 |
| SOCKET數 | 8 | 4 | 4 |
| 收發緩存 | 32KB | 16KB | 16KB |
| MAX速率(Mbps) | 16 | 25 | 25 |
| Sleep mode | O | X | X |
| Hybrid mode | O | O | O |
| 工作溫度 | -40℃ ~ 80℃ | -40℃ ~ 80℃ | -40℃ ~ 80℃ |
| 工作電壓 | 3.3V/5V | 3.3V/5V | 3,3V/5V |
| 性能轉換 | 不支持極性自動轉換 | 支持極性自動轉換 | 支持極性自動轉換 |
| 支持的全硬件TCP\IP協議 | TCP、UDP、IP、ICMP、MAC、IGMP、PPPoE、Ethernet MAC | TCP、UDP、IP、ICMP、MAC、IGMP、PPPoE、Ethernet MAC | TCP、UDP、IP、ICMP、MAC、IGMP、PPPoE、WOL |
| 封裝工藝 | LQFP48 無鉛封裝(7x7mm,間距 0.5mm) | LQFP80 無鉛封裝 | 48 管腳 LQFP 封裝和 QFN 封裝 (無鉛,7x7mm, 0.5mm 間距) |
2. W5100S網卡的TCP-Client回環測試
2.1 CC2652RB硬件SPI的介紹
使用 CC2652RB 的 SDK 開發包提供的例程 ( spimaster ) 加以修改來驅動 W5100S 網卡.
SDK里已經把它所有外設的驅動都封裝成庫,只要按照 <ti/drivers/SPI.h> 文件中提供的說明,按順序調用對應的API即可使用,例如:
/*!****************************************************************************** @file SPI.h** @brief Serial Peripheral Interface (SPI) Driver Interface** @anchor ti_drivers_SPI_Overview* # Overview* The Serial Peripheral Interface (SPI) driver is a generic, full-duplex* driver that transmits and receives data on a SPI bus. SPI is sometimes* called SSI (Synchronous Serial Interface).* The SPI protocol defines the format of a data transfer over the SPI bus,* but it leaves flow control, data formatting, and handshaking mechanisms* to higher-level software layers.** The SPI driver operates on some key definitions and assumptions:* - The driver operates transparently from the chip select. Some SPI* controllers feature a hardware chip select to assert SPI slave* peripherals. See the specific device implementations on chip* select requirements.** - The SPI protocol does not account for a built-in handshaking mechanism* and neither does this SPI driver. Therefore, when operating in* #SPI_SLAVE mode, the application must provide such a mechanism to* ensure that the SPI slave is ready for the SPI master. The SPI slave* must call #SPI_transfer() *before* the SPI master starts transmitting.* Some example application mechanisms could include:* - Timed delays on the SPI master to guarantee the SPI slave is ready* for a SPI transaction.* - A form of GPIO flow control from the slave to the SPI master to notify* the master when ready.** <hr>* @anchor ti_drivers_SPI_Usage* # Usage** To use the SPI driver to send data over the SPI bus, the application* calls the following APIs:* - SPI_init(): Initialize the SPI driver.* - SPI_Params_init(): Initialize a #SPI_Params structure with default* values. Then change the parameters from non-default values as* needed.* - SPI_open(): Open an instance of the SPI driver, passing the* initialized parameters, or NULL, and an index to the configuration to* open (detailed later).* - SPI_transfer(): Transmit/receive data. This function takes a* #SPI_Transaction argument that describes the transfer that is requested.* - SPI_close(): De-initialize the SPI instance.** @anchor ti_drivers_SPI_Synopsis* ## Synopsis* The following code example opens a SPI instance as a master SPI,* and issues a transaction.** @code* SPI_Handle spi;* SPI_Params spiParams;* SPI_Transaction spiTransaction;* uint8_t transmitBuffer[MSGSIZE];* uint8_t receiveBuffer[MSGSIZE];* bool transferOK;** SPI_init(); // Initialize the SPI driver** SPI_Params_init(&spiParams); // Initialize SPI parameters* spiParams.dataSize = 8; // 8-bit data size** spi = SPI_open(CONFIG_SPI0, &spiParams);* if (spi == NULL) {* while (1); // SPI_open() failed* }** // Fill in transmitBuffer* spiTransaction.count = MSGSIZE;* spiTransaction.txBuf = (void *)transmitBuffer;* spiTransaction.rxBuf = (void *)receiveBuffer;** transferOK = SPI_transfer(spi, &spiTransaction);* if (!transferOK) {* // Error in SPI or transfer already in progress.* while (1);* }* @endcode這里僅貼出了一下部分,具體請到對應的 .h 文件中查閱.
2.2 初始化與W5100S連接的接口
通過 SysConfig 工具配置使用到的SPI以及一些控制引腳的IO
配置成功后,點擊 FILE – Save 保存配置內容。
在 utility.h 文件中配置延時函數
注釋掉 utility.c 文件中配置STM32滴答定時器用來延時的函數,并在 utility.h 中使用宏定義定義延時函數
2.3 測試工程主函數
void *masterThread(void *arg0) {int32_t status; // status = sem_init(&masterSem, 0, 0); // if (status != 0) { // Display_printf(display, 0, 0, "Error creating masterSem\n"); // // while(1); // }bsp_HardSpiInit();//W5100S 初始化reset_break_gpio_init();reg_wizchip_spi_cbfunc(bsp_HardSpi_ReadByte,bsp_HardSpi_SendByte); // SPI讀寫數據函數映射reg_wizchip_cs_cbfunc(bsp_W5100sCS_Low,bsp_W5100sCS_High); // SPI片選控制函數映射reset_w5100s(); // W5100S硬件復位PHY_check(); // 網線檢測程序set_w5100s_mac(); // 設置W5100SMAC地址set_w5100s_netinfo(); // 設置W5100S網絡參數sysinit(0x55,0x55); // 初始化4個Socket的發送接收緩存大小for(;;){do_tcp_client(); // TCP 客戶端數據回環測試}bsp_HardSpiClose();/* Example complete - set pins to a known state */GPIO_disableInt(CONFIG_SPI_SLAVE_READY);GPIO_setConfig(CONFIG_SPI_SLAVE_READY, GPIO_CFG_OUTPUT | GPIO_CFG_OUT_LOW);Display_printf(display, 0, 0, "\nDone");return (NULL); }- 完整的工程下載,請點擊 W5100S網卡的TCP-Client回環測試【資料中包含 STM32F103VET6 驅動 W5100S 的模板工程】,如果您沒有積分可以留言,我單獨發您。
PS:
- 使用IAR搭建CC2652RB的開發環境
- IAR FOR ARM 需要 8.50.9 及以上版本才能打開.
- 需要先安裝 CC2652RB 的 SDK,且需要安裝在默認位置(C:\ti).
總結
以上是生活随笔為你收集整理的CC2652RB硬件SPI驱动W5100S网卡进行回环测试的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机信息第三册教案,泰山版小学信息技术
- 下一篇: 音频放大器