i am using a lib for i2c comunication lib from this site
i2c communication tivaware example
I want to communicate atexas instrument launchpad with a ds1307. I did that with an arduino and i need to learn how to do that with texas instruments launchpads.
I want to set two 3 functions:1) to set the control register 2) read the control reg 3) send the hour
#define DS1307_ADDRESS 0x68
#define DS1307_CONTROL 0x07
#define OneHertzSQP 0x10
void RtcSetCTRL(){
I2CSend(DS1307_ADDRESS,2,DS1307_CONTROL,OneHertzSQP);
}
uint32_t RtcReadCTRL()
{
return I2CReceive(DS1307_ADDRESS,DS1307_CONTROL);
}
void RtcDS1307adjust(){
I2CSend(DS1307_ADDRESS,7,
myFullCalendar.seconds,myFullCalendar.minutes,myFullCalendar.hour,
myFullCalendar.dayOfWeek,myFullCalendar.date,myFullCalendar.month,myFullCalendar.year);
where myFullCalendar is a struct.
also there is the init,receive and send functions for the i2c in the site.
I am not concerned about the last function.
I have a led in the pin for the that when i set the control reg to 1Hz it blinks every sec.
This is what i want to see in order to be sure that i use correctly the send recieve functions. So i will be sure i can use every i2c device correctly.
When i debug the program the launchpad stacks in the functions i2csend in the AT THE LINE:
while(I2CMasterBusy(I2C0_BASE)); /////IT STOPS HERE
i give you the code from the site.
void I2CSend(uint8_t slave_addr, uint8_t num_of_args, ...)
{
// Tell the master module what address it will place on the bus when
// communicating with the slave.
I2CMasterSlaveAddrSet(I2C0_BASE, slave_addr, false);
//stores list of variable number of arguments
va_list vargs;
//specifies the va_list to "open" and the last fixed argument
//so vargs knows where to start looking
va_start(vargs, num_of_args);
//put data to be sent into FIFO
I2CMasterDataPut(I2C0_BASE, va_arg(vargs, uint32_t));
//if there is only one argument, we only need to use the
//single send I2C function
if(num_of_args == 1)
{
//Initiate send of data from the MCU
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);
// Wait until MCU is done transferring.
while(I2CMasterBusy(I2C0_BASE));
//"close" variable argument list
va_end(vargs);
}
//otherwise, we start transmission of multiple bytes on the
//I2C bus
else
{
//Initiate send of data from the MCU
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
// Wait until MCU is done transferring.
while(I2CMasterBusy(I2C0_BASE)); /////IT STOPS HERE
//send num_of_args-2 pieces of data, using the
//BURST_SEND_CONT command of the I2C module
uint8_t i;
for(i = 1 ; i < (num_of_args - 1) ; i++)
{
//put next piece of data into I2C FIFO
I2CMasterDataPut(I2C0_BASE, va_arg(vargs, uint32_t));
//send next data that was just placed into FIFO
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
// Wait until MCU is done transferring.
while(I2CMasterBusy(I2C0_BASE));
}
//put last piece of data into I2C FIFO
I2CMasterDataPut(I2C0_BASE, va_arg(vargs, uint32_t));
//send next data that was just placed into FIFO
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
// Wait until MCU is done transferring.
while(I2CMasterBusy(I2C0_BASE));
//"close" variable args list
va_end(vargs);
}
}
Do you find any problem in my functions? Why this does not work? Also i have desolder pull up resistors from the pcb in order to work in 3.3v lauchpad.
Is there any problem on the code that you see?
