Hi All,
can any one works on i2c as a slave with multiple btye recieve ??
i get 1 byte at a time but 2nd byte don't get.
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.
Hi All,
can any one works on i2c as a slave with multiple btye recieve ??
i get 1 byte at a time but 2nd byte don't get.
hi Amit,
tm4c129 act as a slave for i2c and msp430f5529 and msp430f5329 worked as a master.
so i am sending 3 byte by master and slave will read the data and then process it.
i am attaching my slave code for tm4c1294ncpdt. my master code working fine and i am tested in my last project.
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include "inc/tm4c129xnczad.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/i2c.h"
#include "driverlib/interrupt.h"
#include "driverlib/udma.h"
#define SLAVE_ADDRESS 0x3A
unsigned char ui8I2CBuf[10];
int i2c1status=0;
int i2c2status=0;
void I2C5_Init()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PB0_I2C5SCL);
GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_0);
GPIOPinConfigure(GPIO_PB1_I2C5SDA);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C5);
I2CSlaveEnable(I2C5_BASE);
I2CSlaveIntEnableEx(I2C5_BASE, I2C_SLAVE_INT_DATA);
I2CMasterInitExpClk(I2C5_BASE, SysCtlClockGet(), false);
I2CSlaveInit(I2C5_BASE, SLAVE_ADDRESS);
IntMasterEnable();
}
void I2C6_Init()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA6_I2C6SCL);
GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);
GPIOPinConfigure(GPIO_PA7_I2C6SDA);
GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C6);
I2CSlaveEnable(I2C6_BASE);
I2CSlaveIntEnableEx(I2C6_BASE, I2C_SLAVE_INT_DATA);
I2CMasterInitExpClk(I2C6_BASE, SysCtlClockGet(), false);
I2CSlaveInit(I2C6_BASE, SLAVE_ADDRESS);
IntMasterEnable();
}
void I2C5Slave_IntHandler()
{
I2CSlaveIntClear(I2C6_BASE);
i2c1status = 1;
}
void I2C6Slave_IntHandler()
{
I2CSlaveIntClear(I2C7_BASE);
i2c2status = 1;
}
void call_12c(uint32_t Base,int adr)
{
uint32_t state;
state = I2CSlaveStatus(Base);
switch(state)
{
case I2C_SLAVE_ACT_RREQ :
ui8I2CBuf[i] = I2CSlaveDataGet(base);
i++;
while(!adr); // waiting for i2c stop bit
break;
case I2C_SLAVE_ACT_TREQ :
ui8I2CBuf[i] = I2CSlaveDataGet(base);
i++;
while(!adr); // waiting for i2c stop bit
break;
}
}
int main()
{
I2C6_Init();
I2C5_Init();
while(1)
{
if(i2c1status==1)
call_12c(I2C5_BASE,i2c1status);
if(i2c2status==1)
call_12c(I2C6_BASE,i2c2status);
}
}
this is for generic which collect all data form both adc.
HI all,
can any one give me idea about how to get stop bit in I2C act as a slave bit.
i can put my code here.
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include "inc/hw_memmap.h"
#include "inc/hw_adc.h"
#include "inc/hw_types.h"
#include "inc/tm4c129xnczad.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/i2c.h"
#include "i2c_b.h"
#include "memory.h"
#define SLAVE_ADDRESS 0x3A
static unsigned char g_ui8I2CGetBuf[5];
static unsigned char g_ui8I2CPutBuf[5];
int i2cput;
int I2C0Alert;
int I2C5Alert;
int I2C6Alert;
int I2C7Alert;
// init
void SysClk_Init()
{
SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);
}
void I2C0_Init()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
GPIOPinConfigure(GPIO_PB3_I2C0SDA);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
I2CSlaveEnable(I2C0_BASE);
I2CSlaveIntEnableEx(I2C0_BASE, I2C_SLAVE_INT_DATA);
I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false);
I2CSlaveInit(I2C0_BASE, SLAVE_ADDRESS);
I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS, false);
IntMasterEnable();
}
void I2C5_Init()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PB0_I2C5SCL);
GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_0);
GPIOPinConfigure(GPIO_PB1_I2C5SDA);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C5);
I2CSlaveEnable(I2C5_BASE);
I2CSlaveIntEnableEx(I2C5_BASE, I2C_SLAVE_INT_DATA);
I2CMasterInitExpClk(I2C5_BASE, SysCtlClockGet(), false);
I2CSlaveInit(I2C5_BASE, SLAVE_ADDRESS);
I2CMasterSlaveAddrSet(I2C5_BASE, SLAVE_ADDRESS, false);
IntMasterEnable();
}
// vector table handler
void I2C0_IntHandler()
{
I2CSlaveIntClear(I2C0_BASE);
I2C0Alert = 1;
}
void I2C5_IntHandler()
{
I2CSlaveIntClear(I2C5_BASE);
I2C5Alert = 1;
}
// collect data
void ATS_I2C_IntHandler(uint32_t Base,int AlertStatus)
{
uint32_t I2CState;
unsigned char result;
int i=0;
AlertStatus = 0;
I2CState = I2CSlaveStatus(Base);
switch(I2CState)
{
case I2C_SLAVE_ACT_NONE :
break;
case I2C_SLAVE_ACT_RREQ :
g_ui8I2CGetBuf[i] =(unsigned char) I2CSlaveDataGet(Base);
i++;
while(!AlertStatus);
break;
case I2C_SLAVE_ACT_TREQ :
I2CSlaveDataPut(Base,g_ui8I2CPutBuf[i]);
i++;
while(!AlertStatus);
break;
}
}
int main(void)
{
SysClk_Init();
I2C0_Init();
I2C5_Init();
while(1)
{
if(I2C0Alert==1)
{
ATS_I2C_IntHandler(I2C0_BASE,I2C0Alert);
}
if(I2C5Alert==1)
{
ATS_I2C_IntHandler(I2C5_BASE,I2C5Alert);
}
}
}
i need to get stop bit after last data get for reading how much data can come across i2c. in this i2c worked as a slave.
plz help me how to proceed next ??