Tool/software: Code Composer Studio
I have written a simple code for softi2c. Initialise, start and send byte are working fine. Untill i pack the send byte code into a function.
If the send byte function is not made separately but rather pasted in main(), it works and A0 is transmitted successfully.
But soon as i pack it in a function, i get following error:
error #148: declaration is incompatible with "void i2c_send_byte()"
CCSv5
#include "msp430g2210.h"
#define SDA BIT2
#define SCL BIT5
void init_i2c();
void i2c_start();
void i2c_send_byte(A0);
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
init_i2c();
i2c_start();
i2c_send_byte(0xA0); // send A0
while(1); // wait forever
}
void init_i2c()
{
P1DIR |= (SDA + SCL); // Set P2.2 and P2.3 to output direction
}
void i2c_start()
{
P1OUT |= (SDA + SCL);
__delay_cycles(5);
P1OUT &= ~SDA; // SDA=1->0 while SCL=1
}
void i2c_send_byte(unsigned char byte)
{
unsigned char i,tmp; // Variable to be used in for loop
for(i=0;i<8;i++) // Repeat for every bit
{
P1OUT &= ~SCL;
__delay_cycles(1);
tmp=(((byte<<i)&0x80)?(P1OUT|=SDA):(P1OUT&=~SDA)); // Place data bit value on SDA pin depending on 0 or 1 bit
__delay_cycles(1);
P1OUT |= SCL; // Toggle SCL pin so that slave can latch data bit
__delay_cycles(1);
}
// Get ACK from slave
P1OUT &= ~SCL;
P1OUT |= SDA;
__delay_cycles(1);
P1OUT |= SCL;
__delay_cycles(1);
}