Пример #1
0
//*****************************************************************************
//
// Writes a single byte to an address in the I2C-attached EEPROM device.
//
// \param ucAddr is the EEPROM address to write.
// \param ucData is the data byte to write.
//
// This function writes a single byte to the I2C-attached EEPROM on the
// daughter board.  The location to write is passed in parameter \e ucAddr
// where values 0 to 127 are valid (this is a 128 byte EEPROM).
//
// This is not used in this particular application but is included for
// completeness.
//
// \return Returns \b true on success of \b false on failure.
//
//*****************************************************************************
static tBoolean
EEPROMWritePolled(unsigned char ucAddr, unsigned char ucData)
{
    //
    // Start with a dummy write to get the address set in the EEPROM.
    //
    ROM_I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, ID_I2C_ADDR, false);

    //
    // Place the address to be written in the data register.
    //
    ROM_I2CMasterDataPut(I2C0_MASTER_BASE, ucAddr);

    //
    // Start a burst send, sending the device address as the first byte.
    //
    ROM_I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);

    //
    // Wait until the current byte has been transferred.
    //
    if(!WaitI2CFinished())
    {
        return(false);
    }

    //
    // Write the value to be written to the flash.
    //
    ROM_I2CMasterDataPut(I2C0_MASTER_BASE, ucData);

    //
    // Send the data byte.
    //
    ROM_I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);

    //
    // Wait until the current byte has been transferred.
    //
    if(!WaitI2CFinished())
    {
        return(false);
    }

    //
    // Delay 5mS to allow the write to complete.  We should really poll the
    // device waiting for an ACK but this is easier (and this code is only
    // for testcase use so this should be safe).
    //
    SysCtlDelay(ROM_SysCtlClockGet() / (200 * 3));

    //
    // Tell the caller we wrote the required data.
    //
    return(true);
}
Пример #2
0
int I2CRead(unsigned char slave, unsigned char address, unsigned int len, unsigned char * readdata, unsigned int readcnt)
{
unsigned long ulToRead;

	// Start with a dummy write to get the address set in the EEPROM.
	ROM_I2CMasterSlaveAddrSet(I2C_MASTER_BASE, slave, false);

	// Place the address to be written in the data register.
	ROM_I2CMasterDataPut(I2C_MASTER_BASE, address);

	// Perform a single send, writing the address as the only byte.
	ROM_I2CMasterControl(I2C_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);

	// Wait until the current byte has been transferred.
	if(!WaitI2CFinished()) 
	{ 
		return(false); 
	}

	// Put the I2C master into receive mode.
	ROM_I2CMasterSlaveAddrSet(I2C_MASTER_BASE, slave, true);

	// Start the receive.
	ROM_I2CMasterControl(I2C_MASTER_BASE, ((readcnt > 1) ? I2C_MASTER_CMD_BURST_RECEIVE_START :
	I2C_MASTER_CMD_SINGLE_RECEIVE));

	// Receive the required number of bytes.
	ulToRead = readcnt;

	while(ulToRead)
	{
		// Wait until the current byte has been read.
		while(ROM_I2CMasterIntStatus(I2C_MASTER_BASE, false) == 0){}
		// Fixes I2C transactions.. ?
		ROM_SysCtlDelay(1000);

		// Clear pending interrupt notification.
		ROM_I2CMasterIntClear(I2C_MASTER_BASE);

		// Read the received character.
		*readdata++ = ROM_I2CMasterDataGet(I2C_MASTER_BASE);
		ulToRead--;

		// Set up for the next byte if any more remain.
		if(ulToRead)
		{
			ROM_I2CMasterControl(I2C_MASTER_BASE, ((ulToRead == 1) ? I2C_MASTER_CMD_BURST_RECEIVE_FINISH :
			I2C_MASTER_CMD_BURST_RECEIVE_CONT));
		}
	}

	return(readcnt - ulToRead);
}
Пример #3
0
//*****************************************************************************
//
// Reads from the I2C-attached EEPROM device.
//
// \param pucData points to storage for the data read from the EEPROM.
// \param ulOffset is the EEPROM address of the first byte to read.
// \param ulCount is the number of bytes of data to read from the EEPROM.
//
// This function reads one or more bytes of data from a given address in the
// ID EEPROM found on several of the development kit daughter boards.  The
// return code indicates whether the read was successful.
//
// \return Returns \b true on success of \b false on failure.
//
//*****************************************************************************
static tBoolean
EEPROMReadPolled(unsigned char *pucData, unsigned long ulOffset,
                 unsigned long ulCount)
{
    unsigned long ulToRead;

    //
    // Clear any previously signalled interrupts.
    //
    ROM_I2CMasterIntClear(I2C0_MASTER_BASE);

    //
    // Start with a dummy write to get the address set in the EEPROM.
    //
    ROM_I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, ID_I2C_ADDR, false);

    //
    // Place the address to be written in the data register.
    //
    ROM_I2CMasterDataPut(I2C0_MASTER_BASE, ulOffset);

    //
    // Perform a single send, writing the address as the only byte.
    //
    ROM_I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);

    //
    // Wait until the current byte has been transferred.
    //
    if(!WaitI2CFinished())
    {
        return(false);
    }

    //
    // Put the I2C master into receive mode.
    //
    ROM_I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, ID_I2C_ADDR, true);

    //
    // Start the receive.
    //
    ROM_I2CMasterControl(I2C0_MASTER_BASE,
                         ((ulCount > 1) ? I2C_MASTER_CMD_BURST_RECEIVE_START :
                         I2C_MASTER_CMD_SINGLE_RECEIVE));

    //
    // Receive the required number of bytes.
    //
    ulToRead = ulCount;

    while(ulToRead)
    {
        //
        // Wait until the current byte has been read.
        //
        while(ROM_I2CMasterIntStatus(I2C0_MASTER_BASE, false) == 0)
        {
        }

        //
        // Clear pending interrupt notification.
        //
        ROM_I2CMasterIntClear(I2C0_MASTER_BASE);

        //
        // Read the received character.
        //
        *pucData++ = ROM_I2CMasterDataGet(I2C0_MASTER_BASE);
        ulToRead--;

        //
        // Set up for the next byte if any more remain.
        //
        if(ulToRead)
        {
            ROM_I2CMasterControl(I2C0_MASTER_BASE,
                                 ((ulToRead == 1) ?
                                  I2C_MASTER_CMD_BURST_RECEIVE_FINISH :
                                  I2C_MASTER_CMD_BURST_RECEIVE_CONT));
        }
    }

    //
    // Tell the caller we read the required data.
    //
    return(true);
}