/******************** (C) COPYRIGHT 2022 SONiX *******************************
* COMPANY:	SONiX
* DATE:		2022/01/06
* IC:			SN8F5754
*____________________________________________________________________________
* REVISION		Date				Author		Description
* 1.0					2022/01/06	SONiX			1. First release
*____________________________________________________________________________
*****************************************************************************/
/*_____ I N C L U D E S _________________________________*/
#define __XRAM_SFR_H__
#include <SN8F5754.h>
#include "i2c.h"

/*_____ F U N C T I O N S _______________________________*/

/*_____ D E F I N I T I O N S ___________________________*/
#define I2C_PIN_SEL                 0

#define	I2C_SELF_ADDRESS						0x20
#define	I2C_MATE_ADDRESS						0x40


/*_____ D E C L A R A T I O N S _________________________*/
uint8_t	bI2C_RxDataBuf[10];
uint8_t bMN_DataBuf[10];

/*_____ M A C R O S _____________________________________*/


/**
 *	@Brief		main: ADC Test Demo Function
 *	@param		None
 *	@retval		None
 */

void main(void)
{
	/*	Initialize GPIO status	*/
	GPIO_Initialization();															
	
  /*	Initializes and configures the I2C function	*/
	I2C_ConfigureRegister(I2C_PIN_SEL, mskI2CCON_I2C_CLOCKDIV_80, I2C_SELF_ADDRESS, I2C_MATE_ADDRESS);

	/*	Enable global interrupt	*/
	EAL = 1;
	
	/*	Initializes data buf and start to I2C transmittion	*/
  I2C_InitSlave(I2C_RX_SEL, bI2C_RxDataBuf, sizeof(bI2C_RxDataBuf));
  
	while(1)
  {
    /*  Check status and read data */
    if(I2C_CheckReciDataDone())
    {
      bMN_DataBuf[2] = bI2C_RxDataBuf[2];
      /*  get new data  */
      I2C_RepeatSlave();
    }
    else
    {
      /*  Check incomplete tranmission status */
      if(I2C_CheckReciDataStop())
      {
        I2C_RepeatSlave();
      }
    }
  }

}