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.

hello,I am trying to write a program about tm4c123gh6pm's hardware iic interrupt,but i have a problem.Looking forward to your reply,thank you.

///This is the process I see to the program but my interrupt can not go in, I have two questions, one: while (1) inside send ui32DataTx, is using I2CMasterControl(I2C0_BASE, //I2C_MASTER_CMD_BURST_SEND_START);// configure interrupt source:

// I2CSlaveIntEnableEx (I2C0_BASE I2C_SLAVE_INT_DATA);

//I2c_slave_int_stop-stop condition detects interrupt

// i2c_slave_int_start-start condition detects interrupt

// I2C_SLAVE_INT_DATA - data interrupt

// what is the meaning of these three respectively

///Here is my program

#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_i2c.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/i2c.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#define LED_ON GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0XFF);
//定义从机地址
#define SLAVE_ADDRESS 0x3C
#define g_bIntFlag 0
//接收的数据
uint32_t g_ui32DataRx;
//中断标志位


//串口初始化函数
void InitConsole(void)
{

SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
}

//中断处理函数
void I2C0SlaveIntHandler(void)
{
//清除中断标志位
I2CSlaveIntClear(I2C0_BASE);
// Read the data from the slave.
g_ui32DataRx = I2CSlaveDataGet(I2C0_BASE);
LED_ON;
// Set a flag to indicate that the interrupt occurred.
// g_bIntFlag = 1;

}
void LED_init (void)
{
SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
}

// Configure the I2C0 master and slave and connect them using loopback mode.
int main(void)
{
uint32_t ui32DataTx;
//外部晶振作为时钟源 16MHZ
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
LED_init ();
//////////使能IIC
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinConfigure(GPIO_PB3_I2C0SDA);

GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);

// Enable loopback mode.
HWREG(I2C0_BASE + I2C_O_MCR) |= 0x01;

// Enable the I2C0 interrupt on the processor (NVIC).
IntEnable(INT_I2C0);
// 配置中断源:从机接收到数据产生中断 I2C_SLAVE_INT_STOP - Stop条件检测到中断
// I2C_SLAVE_INT_START - Start条件检测到中断
// I2C_SLAVE_INT_DATA -数据中断
I2CSlaveIntEnableEx(I2C0_BASE,I2C_SLAVE_INT_DATA);

// 使能并初始化I2C0的主模块,I2C0模块使用系统时钟。
//语句的最后一个参数是用来设定数据传输速率的。false表示传输速率是100kbps,true则意味着传输速率是400kbps。
I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false);

// Enable the I2C0 slave module.
I2CSlaveEnable(I2C0_BASE);
//从机地址
I2CSlaveInit(I2C0_BASE, SLAVE_ADDRESS);

//false:主模块发送,从模块接收
I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS, false);

// InitConsole();
IntMasterEnable();

ui32DataTx = 0x33;
// 把将发送的数据存入数据寄存器中


while(1)
{
I2CMasterDataPut(I2C0_BASE, ui32DataTx);

// 主模块开始发送数据 ,模式:主机发送单字节数据
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
//UARTCharPut(UART0_BASE, g_bIntFlag );

// Wait for interrupt to occur.
// while(g_bIntFlag);
}
}

////中文

//这就是我看的给的历程的程序但是 我的中断进不去,我有两个疑问,一:while(1)里面 发送 ui32DataTx 后,是用I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);

//二:// 配置中断源:
//I2CSlaveIntEnableEx(I2C0_BASE,I2C_SLAVE_INT_DATA);

//从机接收到数据产生中断 I2C_SLAVE_INT_STOP - Stop条件检测到中断

// I2C_SLAVE_INT_START - Start条件检测到中断
// I2C_SLAVE_INT_DATA -数据中断

//这 三个 分别什么意思 我在库文件里没找到回答

////ENGLISH

///This is the process I see to the program but my interrupt can not go in, I have two questions, one: while (1) inside send ui32DataTx, is using I2CMasterControl(I2C0_BASE, //I2C_MASTER_CMD_BURST_SEND_START);// configure interrupt source:

// I2CSlaveIntEnableEx (I2C0_BASE I2C_SLAVE_INT_DATA);

//I2c_slave_int_stop-stop condition detects interrupt

// i2c_slave_int_start-start condition detects interrupt

// I2C_SLAVE_INT_DATA - data interrupt

// what is the meaning of these three respectively

  • Hi,
    Are you asking what is the difference between I2CMasterDataPut and I2CMasterControl? If this is the question then I2CMasterDataPut is merely to put the data that you want to send in the I2CMDR register. The I2CMasterControl is the one to really carry out the I2C transmission on the bus. The I2C transmission includes the address byte and then the data byte. Depending on what type of command you specify on the I2CMasterControl, the I2C can act differently. If you specify the command I2C_MASTER_CMD_BURST_SEND_START then the I2C will not terminate the transmission as to end the transmission with a STOP bit. It just send the address and the the first data byte and then the I2C bus will just stay low afterward. You will need to send a final I2C_MASTER_CMD_BURST_SEND_FINISH command to end the transmission. If you only have one byte of data to send then you can issue I2C_MASTER_CMD_SINGLE_SEND command.

    Read this app note and it will clarify for your understanding about how to use the Tiva I2C for various types of commands to issue. www.ti.com/.../spma073.pdf
  • Hi,I aleardy know the I2CMasterControl,thank you .But i still not understand the iic's interrupt how to configuration.And the difference about I2C_SLAVE_INT_STOP - Stop条件检测到中断
    // I2C_SLAVE_INT_START - Start条件检测到中断
    // I2C_SLAVE_INT_DATA -数据中断
  • Hi,
    Below are the differences between the three types of interrupt. Please review the I2C protocol first if this is new to you.
    - I2C_SLAVE_INT_STOP means the I2C slave has detected a STOP condition. The slave detected the SDA line switches from a high voltage level to a low voltage level before the SCL line switches from high to low.
    - I2C_SLAVE_INT_START means the I2C slave has detected a START condition. The slave detected SDA line switches from a low voltage level to a high voltage level after the SCL line switches from low to high.
    - I2C_SLAVE_INT_DATA means the I2C will generate an interrupt when either the data has been received or requested.
  • I have received the document you sent me. And I now want to configure FIFO for hardware IlC's interrupt.l checked a lot of library fles and processes but couldntfind them.l am looking forward to your reply
  • Hi,
    There is no FIFO in the I2C module and this is why you can't find it. Some other communication peripherals like UART, SSI do have FIFO, but not I2C.

    By the way, are you clear on the interrupt now? The slave generates interrupts when data has been transferred or requested by a master or when a START of STOP condition is detected.

    If your question about the interrupt is answered then i will close this thread.
  • Hi,
    I didn't hear back from you. I assume I answered your question. To reiterate again, there is no FIFO in the I2C module. The slave generates interrupts when data has been transferred or requested by a master or when a START of STOP condition is detected. I'm closing this thread. If you have new question you can create a new thread for support.