This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
大家好、
IAM 尝试在 TM4C1294 EVK (免费 RTOS + LWIP)中进行以太网通信、以便使用演示代码 Enet_tcpecho_client_lwip (无免费 RTOS)、
所以、我曾尝试将免费 RTOS 与以太网接收 和发送任务集成在一起、但在连接建立阶段我的代码却受到了冲击。
我只需要一个演示项目(免费 RTOS + LWIP + TM4C1294 EVK +以太网 客户端发送 和接收 任务),这样我就可以尝试确定 API 步骤并尝试解决问题
当前 IAM 使用以下工程、但不含免费 RTOS 的演示工程
采取必要措施解决问题
您好!
我只需要一个演示项目(免费 RTOS + LWIP + TM4C1294 EVK +以太网 客户端发送 和接收 任务),这样我就可以尝试确定 API 步骤并尝试解决问题[/报价]抱歉、我们没有免费 RTOS + LWIP + TM4C1294 EVK +以太网 客户端 TM4C129的发送和接收任务这样的项目。 非 RTOS RAW Enet_tcpecho_client_lwip 是我们针对 lwIP 提供的唯一客户端示例。
团队成员
//============================================================================ // Name : i2cAPI.c // Author : // Version : // Copyright : Your copyright notice // Description : Tiva i2c in C++, Ansi-style //============================================================================ /* * i2cAPI.c * Implementation of a i2c interface * * Copyright * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL I * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <stdint.h> #include <stdio.h> #include <stdbool.h> #include "i2cAPI.h" #include "driverlib/inc/tm4c1294kcpdt.h" #include "driverlib/inc/hw_i2c.h" #include "driverlib/inc/hw_memmap.h" #include "driverlib/inc/hw_types.h" #include "driverlib/inc/hw_gpio.h" #include "driverlib/i2c.h" #include "driverlib/sysctl.h" #include "driverlib/gpio.h" #include "driverlib/pin_map.h" #include "driverlib/rom_map.h" #include "utils/uartstdio.h" uint32_t i2c_init(uint32_t g_ui32SysClock) { //This function is for eewiki and is to be updated to handle any port // Enable peripherals in use. Also reset I2C2 at the end to allow calling // this function at any point in order to reset I2C interface. MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C8); // Enable I2C communication interface, SCL, SDA lines MAP_GPIOPinConfigure(GPIO_PD2_I2C8SCL); MAP_GPIOPinConfigure(GPIO_PD3_I2C8SDA); MAP_GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_2); MAP_GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_3); // Enable I2C master interface MAP_I2CMasterEnable(I2C8_BASE); // Run I2C bus in high-speed mode, 400kHz speed MAP_I2CMasterInitExpClk(I2C8_BASE, g_ui32SysClock, true); /*//enable GPIO peripheral that contains I2C SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOD)) { UARTprintf("I2c master busy Init\r\n"); break; } // Configure the pin muxing for I2C0 functions on port B2 and B3. GPIOPinConfigure(GPIO_PD2_I2C8SCL); GPIOPinConfigure(GPIO_PD3_I2C8SDA); // Select the I2C function for these pins. GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_2); GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_3); //I2CMasterEnable( I2C8_BASE ); // Enable and initialize the I2C0 master module. Use the system clock for // the I2C0 module. The last parameter sets the I2C data transfer rate. // If false the data rate is set to 100kbps and if true the data rate will // be set to 400kbps. //I2CMasterInitExpClk(I2C8_BASE, SysCtlClockGet(), false); SysCtlPeripheralDisable(SYSCTL_PERIPH_I2C8); SysCtlPeripheralReset(SYSCTL_PERIPH_I2C8); SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C8); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOD)) { UARTprintf("I2c master busy Init_1\r\n"); break; } I2CMasterInitExpClk(I2C8_BASE, g_ui32SysClock, true); */ //clear I2C FIFOs /*HWREG(I2C8_BASE + I2C_O_FIFOCTL) = 80008000;*/ } void i2c_read_byte(uint16_t device_address, uint16_t device_register, uint8_t *pui32DataRx) { i2c_read_multi(device_address,device_register,pui32DataRx,1); } void i2c_write_byte(uint16_t device_address, uint16_t device_register, uint8_t pui32DataTx) { uint8_t ui8DataTx = pui32DataTx; i2c_write_multi(device_address,device_register,&ui8DataTx,1); } void i2c_read_multi(uint16_t device_address, uint16_t device_register, uint8_t *pui32DataRx,uint8_t nNumbytes) { uint32_t I2cbaseregAddr = I2C0_BASE; //specify that we want to communicate to device address with an intended write to bus I2CMasterSlaveAddrSet(I2cbaseregAddr, device_address, false); //the register to be read I2CMasterDataPut(I2cbaseregAddr, device_register); //send control byte and register address byte to slave device I2CMasterControl(I2cbaseregAddr, I2C_MASTER_CMD_SINGLE_SEND); //wait for MCU to complete send transaction while(I2CMasterBusy(I2cbaseregAddr)) { UARTprintf("I2c master busy\r\n"); } //read from the specified slave device I2CMasterSlaveAddrSet(I2cbaseregAddr, device_address, true); //send control byte and read from the register from the MCU I2CMasterControl(I2cbaseregAddr, I2C_MASTER_CMD_SINGLE_RECEIVE); //wait while checking for MCU to complete the transaction while(I2CMasterBusy(I2cbaseregAddr)) { UARTprintf("I2c master busy\r\n"); } // Dummy acknowledge and wait for the receive request from the master. // This is done to clear any flags that should not be set. // while(!(I2CSlaveStatus(I2cbaseregAddr) & I2C_SLAVE_ACT_TREQ)) { } if(nNumbytes == 1) { pui32DataRx[nNumbytes] = I2CMasterDataGet(I2cbaseregAddr); } else if(nNumbytes > 1) { for(ui32Index = 0; ui32Index < nNumbytes; ui32Index++) { // // Read the data from the master. // pui32DataRx[ui32Index] = I2CMasterDataGet(I2cbaseregAddr); // // Display the data that the slave has received. // //UARTprintf("Received: '%c'\n", pui32DataRx[ui32Index]); } } } void i2c_write_multi(uint16_t device_address, uint16_t device_register, uint8_t* pui32DataTx,uint8_t nNumbytes) //uint32_t pui32DataTx[NUM_I2C_DATA]; { uint32_t I2cbaseregAddr = I2C0_BASE; //specify that we want to communicate to device address with an intended write to bus I2CMasterSlaveAddrSet(I2cbaseregAddr, device_address, false); //register to be read I2CMasterDataPut(I2cbaseregAddr, device_register); //send control byte and register address byte to slave device I2CMasterControl(I2cbaseregAddr, I2C_MASTER_CMD_BURST_SEND_START); //wait for MCU to finish transaction while(I2CMasterBusy(I2cbaseregAddr)); I2CMasterSlaveAddrSet(I2cbaseregAddr, device_address, true); //specify data to be written to the above mentioned device_register while(nNumbytes--) { // // Place the data to be sent in the data register // I2CMasterDataPut(I2cbaseregAddr, pui32DataTx); UARTprintf(" Sending: '%c' . . . ", pui32DataTx); // // Initiate send of data from the master. Since the loopback // mode is enabled, the master and slave units are connected // allowing us to receive the same data that we sent out. // I2CMasterControl(I2cbaseregAddr, I2C_MASTER_CMD_SINGLE_SEND); // // Wait until the slave has received and acknowledged the data. // while(!(I2CSlaveStatus(I2cbaseregAddr) & I2C_SLAVE_ACT_RREQ)) { UARTprintf("I2c NACK\r\n"); } pui32DataTx++; } //wait while checking for MCU to complete the transaction I2CMasterControl(I2cbaseregAddr, I2C_MASTER_CMD_BURST_RECEIVE_FINISH); //wait for MCU & device to complete transaction while(I2CMasterBusy(I2cbaseregAddr)); { UARTprintf("I2c master busy\r\n"); } }
几个问题:
-在第52-71行之间,你初始化 I2C8。 但在76-108之间、您可以再次初始化 I2C8。 为什么要这样做?
-在你的128和188行,你硬编码 I2C0。 我想在 i2c_init()中启动 I2C8时使用 I2C8。 如果要使用 I2C0、I2C0的初始化在哪里? 这就是它不起作用的原因。
-确保您电路板上的 SDA 和 SDL 具有正确的上拉电阻,用于您要使用的 I2C 总线(例如 I2C8SDA 和 I2C8SCL)。
BTW、如果您对 I2C 有新问题、则应打开新主题进行讨论。 您不仅仅拒绝了我两周前关于以太网的回答。