Other Parts Discussed in Thread: EK-TM4C123GXL
Tool/software: Code Composer Studio
I'm trying to interface MCP401XEV EVALUATION BOARD (which has digital Resistor inside, MCP40D18) with my microcontroller Tiva C Launchpad(TM4C123GH6PM) with the I2C Interface:
Master : I2C module 0, which is GPIO Port B , pin 2(SCL) pin 3(SDA).
Slave : digital POT(MCP401XEV) which has Slave address (0x7C)
i want to send one single Byte to my digital POT and then read the V(out) from it.
each time i measure i see the middle value , which means that no data transmitted by Master and received by Slave and when i see the value of I2CMDR Register in CCS i notice that this register does not update at all .
i saw that somebody else had the same problem and i did what i had to , like make a breakpoint befor and after writing to I2CMDR :: I2CMasterDataPut(uint32_t ui32Base,uint8_t ui8Data) or setting the GPIO_DEN for PB2,PB3 but it didn't work.
if somebody can help me i would be very very thankfull because this problem for such a simple code and simple use of I2C interface driving me crazy .
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_i2c.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "driverlib/i2c.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#define GPIO_PORTB_DEN_R (*((volatile unsigned long *)0x4000551C)) // GPIO Digital Enable(8bits)//
void InitI2C0(void){
//enable I2C module 0
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
//reset module
SysCtlPeripheralReset(SYSCTL_PERIPH_I2C0);
//enable GPIO peripheral that contains I2C 0
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
//GPIO_PORTB_DEN_R |= 0xFF; // enable digital I/O on PB2,3 (i just wanted to show that i setted also DEN for PB2,PB3)
// Configure the pin muxing for I2C0 functions on port B2 and B3.
GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinConfigure(GPIO_PB3_I2C0SDA);
// Select the I2C function for these pins.
GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
// 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(I2C0_BASE, SysCtlClockGet(), false);
//clear I2C FIFOs
HWREG(I2C0_BASE + I2C_O_FIFOCTL) = 80008000;
}
int main(void){
SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); //Set Clock Frequency at 50MHz
InitI2C0();
I2CMasterSlaveAddrSet(I2C0_BASE, 0x7C, false);
I2CMasterDataPut(I2C0_BASE, 0x5A);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);
while(I2CMasterBusy(I2C0_BASE));
}
