Build error: 'i2c_sendbyte': requires ANSI-style prototype

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hello everyone,

                      iam new to psoc and iam facing error :  Build error: 'i2c_sendbyte': requires ANSI-style prototype

   

THIS IS THE CODE

#include<project.h>

#include"i2c.h"

uint8 i2c_Send(uint8 Address,uint8 *Data,uint8 Num)

{

i2c_start();

//-- Send Addresss

i2c_sendbyte(Address & 0xFE);   //-- Lowest bit = 0 => WRITE    //error line

if(!i2cgetack())

{

  i2cstop();

  return(0);

}

while(Num--)

{

  i2c_sendbyte(*Data);

  if(!i2cgetack())

  {

   i2cstop();

   return(0);

  }

  Data++;

}

i2cstop();

return(1);

}

uint8 i2c_Read(uint8 Address,uint8 *Data, char Num)

{

i2c_start();

//-- Send Address

i2csendbyte(Address | 0x01);   //-- Lowest bit = 1 => READ

if(!i2c_getack())

{

  i2cstop();

  return(0);

}

while(Num--)

{

  *Data=i2c_getbyte();

  Data++;

  if(Num > 0)

  {

   i2c_sendack();

  }

}

i2c_stop();

return(1);

}

uint8 i2c_getbyte(void)

{

char count,Byte=0;

int delay;

SCL_Write(0);

SDA_SetDriveMode(SDA_DM_OD_LO);

for(delay=0;delay<I2CCLOCKLOW;delay++);

//i2cdelay(I2CCLOCKLOW);         //-- Minimum Clock Low Time

for(count=8;count>0;count--)   //-- Read 8 bits of data

{

  Byte=Byte <<1;

  SDA_SetDriveMode(SDA_DM_DIG_HIZ);

  if(i2creadbit())

  {

   Byte +=1;

  }

}

return(Byte);

}

char i2c_readbit(void)

{

char Data=0;

int delay;

//i2cdelay(I2CDATASETTLE);       //-- Minimum Clock Low Time

  for(delay=0;delay<I2CDATASETTLE;delay++);

SCL_Write(1);

//i2cdelay(I2CHALFCLOCK);        //-- 1/2 Minimum Clock High Time

  for(delay=0;delay<I2CHALFCLOCK;delay++);

if(SDA_Read() !=0 ) Data=1;           //-- READ in the data bit

//i2cdelay(I2CHALFCLOCK);        //-- 1/2 Minimum Clock High Time

  for(delay=0;delay<I2CHALFCLOCK;delay++);

SCL_Write(0);

//i2cdelay(I2CCLOCKLOW);         //-- Minimum Clock Low Time

  for(delay=0;delay<I2CCLOCKLOW;delay++);

return(Data);

}

void i2c_sendack(void)

{

  int delay;

 

//--- Send Ack to slave except for last time ---

  SDA_SetDriveMode(SDA_DM_OD_LO);

//i2cdelay(I2CDATASETTLE);      //-- Give it time to settle

  for(delay=0;delay<I2CDATASETTLE;delay++);

i2cclock();                   //-- Pulse the clock

SDA_SetDriveMode(SDA_DM_DIG_HIZ);

//i2cdelay(I2CDATASETTLE);      //-- Gap between next byte

  for(delay=0;delay<I2CDATASETTLE;delay++);

}

//************** END OF i2csendack

void i2c_stop(void)

{

  int delay;

 

  //-- Generate Stop Condition --

SDA_SetDriveMode(SDA_DM_OD_LO);

SCL_Write(1);

//i2cdelay(I2CSTOPDELAY);

  for(delay=0;delay<I2CSTOPDELAY;delay++);

SDA_SetDriveMode(SDA_DM_DIG_HIZ);

}

void i2c_start(void)

{

int delay;

//data goes low with clock high - start condition

SDA_SetDriveMode(SDA_DM_OD_LO);

//i2cdelay(I2CCLOCKLOW);         //-- Minimum Clock Low Time

  for(delay=0;delay<I2CCLOCKLOW;delay++);

}

/*void i2c_delay(int delay)

{

int i;

for(i = 0;i < delay;i++);

}*/

void i2c_sendbyte(uint8 Byte)

{

char count;

int delay;

SCL_Write(0);

//i2cdelay(I2CCLOCKLOW);         //-- Minimum Clock Low Time

   for(delay=0;delay<I2CCLOCKLOW;delay++);

for(count=8;count>0;count--)   //-- Send 8 bits of data

{

  if( (Byte & 0x80)== 0)        //-- Get the Bit

  {

SDA_SetDriveMode(SDA_DM_OD_LO);

                  //-- Ensure Port pin is low

  }

  else

  {

SDA_SetDriveMode(SDA_DM_DIG_HIZ);

             //-- Release pin if bit = 1

  }

  Byte=Byte<<1;                 //-- Shift next bit into position

  i2cclock();                   //-- Pulse the clock

/*

  //for(delay=0;delay<I2CDATASETTLE;delay++);

  SCL_Write(1);

// for(delay=0;delay<I2CCLOCKHIGH;delay++);

  SCL_Write(0);

  //for(delay=0;delay<I2CCLOCKLOW;delay++);

  */

}

//SDA_TRIS=I2CHIGH;              //-- Release data pin for ACK

SDA_SetDriveMode(SDA_DM_DIG_HIZ);

}

void i2c_clock(void)

{

//int delay;

//i2cdelay(I2CDATASETTLE);       //-- Minimum Clock Low Time

// for(delay=0;delay<I2CDATASETTLE;delay++);

SCL_Write(1);

//i2cdelay(I2CCLOCKHIGH);        //-- Minimum Clock High Time

// for(delay=0;delay<I2CCLOCKHIGH;delay++);

SCL_Write(0);

//i2cdelay(I2CCLOCKLOW);         //-- Minimum Clock Low Time

//  for(delay=0;delay<I2CCLOCKLOW;delay++);

}

char i2c_getack(void)

{

  int i,j;

  int dat;

  int delay;

SCL_Write(0);

//i2cdelay(I2CCLOCKLOW);         //-- Minimum Clock Low Time

  for(delay=0;delay<I2CCLOCKLOW;delay++);

SCL_Write(1);

//i2cdelay(I2CHALFCLOCK);          //-- wait for 1/2 the clock pulse

//i2cdelay(22);          //-- wait for 1/2 the clock pulse

for(i = 0;i < 2000;i++)

{

for(j = 0; j<10;j++);

dat = SDA_Read();

if(!dat)

break;

}

//if(SDA_Read())                          //-- sample the ACK signal

if(dat)                          //-- sample the ACK signal

{/

  return(0);                      //-- No ACK so return BAD

}

//i2cdelay(I2CHALFCLOCK);          //-- Else wait for rest of clock

   for(delay=0;delay<I2CHALFCLOCK;delay++);

SCL_Write(0);                 //-- Finish the clock pulse

//i2cdelay(I2CCLOCKLOW);           //-- Minimum Clock Low Time

//i2cdelay(I2CCLOCKLOW);           //-- Minimum Clock Low Time

   for(delay=0;delay<I2CCLOCKLOW;delay++);

  for(delay=0;delay<I2CCLOCKLOW;delay++);

return(1);

}

/* [] END OF FILE */

please help me

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Can you please post your complete project so that we all can have a look at all of your settings. To do so, use

Creator->File->Create Workspace Bundle (minimal)

and attach the resulting file.

Btw:

I2C_Start() (capital "S") and other APIs

Bob

View solution in original post

0 Likes
3 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Can you please post your complete project so that we all can have a look at all of your settings. To do so, use

Creator->File->Create Workspace Bundle (minimal)

and attach the resulting file.

Btw:

I2C_Start() (capital "S") and other APIs

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I solved above error.when i solving above error new error comes.i tried too many times to slove but i can't.Actually iam creating new i2c component based on my project.when i debugging i2c.c files it show error

Build error: PARSING SOURCE-FILE PREPROCESSOR: MACROS TOO NESTED .

kindly let me know what does this error mean. How to rectify this.

0 Likes

Building a new component is not as easy as you did. Read the "Component Author Guide" to learn how it is done. I would suggest strongly to use the provided (and tested!) components.

The error you get results from a multiple expanding of i2c.h. Look at the generated headers to see how this is avoided uzsing a common way.

Bob

0 Likes