QuestionQuestion

1. Suppose you would like to implement I2C, but unfortunately you do not have access to the I2C peripheral. Therefore, you have to implement the protocol in software. Assuming you are using Arduino pin 6 for SCK and Arduino Pin 7 for SDA write the necessary code for a., b., and c. (you can assume the pins are already set up as outputs)

a. void IICWriteClockLine(int value)
//Write the I2C clock line, value=(0,1) means (low,high) {...}

b. void IICWriteDataLine(int value)
//Write the I2C data line, value=(0,1) means (low,high) {...}

c. int IICReadDataLine(void)
//Read the I2C data line, return=(0,1) means (low,high) {...}

You also have setup these two timer ISRs that fire at transitions of a 100kHz time and an I2C Hail function: (They are already attached to the interrupts, no need to set that up)

d. void TimerTransitHighToLow(void)
    //ISR {...}
e. void TimerTransitLowToHigh(void)
    //ISR {...}
f. int HailIIC(unsigned char address)
    {...}
   //Send a 1 byte write request to see if “address” //acknowledges.
   //return=(0,1) means (nack,ack)

Implement both the ISRs in (d.) and (e.) as well as the HailIIC function in (f.) such that the HailIIC function uses the ISRs to control the I2C Data and Clock line. It should generate a start condition, followed by a write request to slave I2C address 0x74, then reads the ack/nack bit, and finally ending with a stop condition. The function should return 0 if the I2C slave nacks or a 1 indicating an ack was received. You can add global or local flags and variables as necessary to keep track of the state or any other conditions. You do not have to implement the functions in (a.), (b.) or (c.). Also, be sure to explain any assumptions that you make in the I2C protocol.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#define SCK 6
#define SDA 7

int data_flag = 0;
int clock_status = 0;

void IICWriteClockLine(int value)
{
if(value==1)
{
    digitalWrite(SCK, HIGH);
}
else
{
    digitalWrite(SCK, LOW);
}

}

void IICWriteDataLine(int value)   
{
pinMode(SDA, OUTPUT);
if(value==1)
{
    digitalWrite(SDA, HIGH);
}
else
{
    digitalWrite(SDA, LOW);
}
}


int IICReadDataLine(void)
{
pinMode(SDA, INPUT);
return digitalRead(SDA);


}
int HailIIC(unsigned char address)
{
int i = 0;
int ack;

IICWriteClockLine(0);
IICWriteDataLine(0); // start the transmission

//wait 1 cycle
TCNT1=0;
TIMSK1 |= (1 << OCIE1A);
IICWriteDataLine(0);
IICWriteClockLine(0);
while(clock_status == 0);
clock_status = 0;


for(i=0;i<8;i++)
{
    TCNT1=0;
    TIMSK1 |= (1 << OCIE1A);
   
   
    if((address & (1 << (i))) != 0)
    {
      IICWriteDataLine(1);
    }else
    {
      IICWriteDataLine(0);
    }

    IICWriteClockLine(1);
   
   
    while(clock_status == 0);
    clock_status = 0;
   
}...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$75.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Digital Electronics Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats