CART
  • Cart is empty.

    ItemQuantityPrice

    Total: $0

I2C RTC test


RTC test on MMC/RTC peripheral board.
Note. To run this test it is necessay to uncomment I2C_RTC_WRITE_TEST in i2c library.

Toolkit:STM Development System

Location:/bipom/devtools/STM32/examples/i2c_rtc

Code Example


int main(void) 
{
	delayMs(250);

	tprintf("\n\rMini-Max/STM32F1");
	tprintf("\n\rI2C RTC TEST REV 1.01");

	SOFT_I2C_RTC_Test();

	return 0;
}


/********************************************************************************************
;	Function:		SOFT_I2C_PrintData
;
;	Description:	Prints data buffer  
;
;	Inputs: 	 	buffer - pointer to data buffer
;					length - length of data buffer 
;
;	Returns:		Nothing	 	 
**********************************************************************************************/
void SOFT_I2C_ATTRIBUTE SOFT_I2C_PrintData( UBYTE* buffer, UINT length)
{
	UINT ndx;
	for( ndx = 0; ndx < length ; ndx++)	
	{
		if (!(ndx%16)) tprintf("\n\r%04x",ndx);
		tprintf (" %02x",*buffer++);
	}
}


/********************************************************************************************
;	Function:		SOFT_I2C_Test
;
;	Description:	Tests AT24C04
;
;	Inputs: 	 	Nothing
;
;	Returns:		Nothing	 
**********************************************************************************************/
void SOFT_I2C_ATTRIBUTE SOFT_I2C_Test(void) 
{
	I2C_ERRCODE ec;
	UINT address;
	UBYTE pBuf[I2C_SIZE];
	//

	//

	tprintf("\n\r\n\r***I2C TEST***");
//	for (;;)

//	{

//		SOFT_SDA_OUTPUT;

//		SOFT_SDA_INPUT;

//		SOFT_SCL_OUTPUT;

//		SOFT_SCL_INPUT;

//	}

#ifdef I2C_WRITE_TEST	
// WRITE TEST 

	tprintf ("\n\rWriting.");
	for(address =0; address < I2C_SIZE; address++) pBuf[address]=0;
	//

	for(address =0; address < I2C_SIZE; address++)
	{
		ec = Soft_WriteAT24C04 (address,(address>>8)&0xFF);
		if(I2C_SUCCESS!=ec)
		{
			tprintf ("\n\rFAILED, addr=%d ec=%d",address,ec);
			break;
		}
		else 
		{
			if (!(address%32)) tprintf (".");
		}
		//

		SoftI2cDelay(10000);
	}
	if(I2C_SUCCESS==ec)
	{
		tprintf ("OK");
	}
#endif	
#ifdef I2C_READ_TEST
// READ TEST

	tprintf ("\n\rReading.");
	for(address =0; address < I2C_SIZE; address++) pBuf[address]=0;
	//

	ec = Soft_ReadAT24C04 (0,pBuf,I2C_SIZE);
	if(I2C_SUCCESS!=ec)
	{
		tprintf ("\n\rFAILED,ec=%d",ec);
	}
	if(I2C_SUCCESS==ec)
	{
		tprintf ("OK");
	}
	//

	tprintf ("\n\rVerifying.");
	for(address =0; address < I2C_SIZE; address++)
	{
		if(pBuf[address]!=((address>>8)&0xFF))
		{
			tprintf ("\n\rFAILED, addr=%d ec=%d",address,ec);
			break;
		}
		else 
		{
			if (!(address%32)) tprintf (".");
		}
	}
	if(I2C_SUCCESS==ec)
	{
		tprintf ("OK");
		SOFT_I2C_PrintData(pBuf,I2C_SIZE);
	}
#endif	
}


/********************************************************************************************
;	Function:		SOFT_I2C_RTC_Test
;
;	Description:	Tests external RTC
;
;	Inputs: 	 	Nothing
;
;	Returns:		Nothing	 
**********************************************************************************************/
void SOFT_I2C_ATTRIBUTE SOFT_I2C_RTC_Test(void) 
{
	I2C_ERRCODE ec;
	UINT address;
	UBYTE pBuf[I2C_RTC_SIZE];
	//

	//

	tprintf("\n\r\n\r***I2C RTC TEST***");
	Soft_I2C_Config(&I2C_SETTINGS);
//	for (;;)

//	{

//		SOFT_SDA_OUTPUT;

//		SOFT_SDA_INPUT;

//		SOFT_SCL_OUTPUT;

//		SOFT_SCL_INPUT;

//	}

#ifdef I2C_RTC_WRITE_TEST	
// WRITE TEST 

	tprintf ("\n\rWriting.");
	for(address =0; address < I2C_RTC_SIZE; address++) pBuf[address]=0;
	//

	for(address =0; address < I2C_RTC_SIZE; address++)
	{
		ec = Soft_WriteRTC(address,(address>>8)&0xFF);
		if(I2C_SUCCESS!=ec)
		{
			tprintf ("\n\rFAILED, addr=%d ec=%d",address,ec);
			break;
		}	
		//

	}
	if(I2C_SUCCESS==ec)
	{
		tprintf ("OK");
	}
#endif	
#ifdef I2C_RTC_READ_TEST
READ_TEST:
	tprintf ("\n\rReading.");
	for(address =0; address < I2C_RTC_SIZE; address++) pBuf[address]=0;
	//

	for(address =0; address < I2C_RTC_SIZE; address++) 
	{
		ec = Soft_ReadRTC (address,&pBuf[address]);
		if(I2C_SUCCESS!=ec)
		{
			tprintf ("\n\rFAILED,addr=%d ec=%d",address,ec);
			break;
		}
		
	}
	if(I2C_SUCCESS==ec)
	{
		tprintf ("OK Seconds= %02x", pBuf[RTC_SECOND_LOCATION]);
	}
	//

	
	delayMs(500);
	goto READ_TEST;
#endif	
}