Question
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 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;
   
}
This is only a preview of the solution.
Please use the purchase button to see the entire solution.
By purchasing this solution you'll be able to access the following files:
Solution.zip
Purchase Solution
$75.00
Google Pay
Amazon
Paypal
Mastercard
Visacard
Discover
Amex
View Available Computer Science Tutors 640 tutors matched
Ionut
(ionut)
Master of Computer Science
Hi! MSc Applied Informatics & Computer Science Engineer. Practical experience in many CS & IT branches.Research work & homework
5/5 (6,804+ sessions)
1 hour avg response
$15-$50 hourly rate
Pranay
(math1983)
Doctor of Philosophy (PhD)
Ph.D. in mathematics and working as an Assistant Professor in University. I can provide help in mathematics, statistics and allied areas.
4.6/5 (6,680+ sessions)
1 hour avg response
$40-$50 hourly rate
Leo
(Leo)
Doctor of Philosophy (PhD)
Hi! I have been a professor in New York and taught in a math department and in an applied math department.
4.9/5 (6,428+ sessions)
2 hours avg response

Similar Homework Solutions