///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