TWI not working

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,
I used the twi driver in AVR1308 app note for an xmega128d3. I have a little test program that send a message out on the twi interface but I do not see anything coming out on the SDA & SCL line. Is there something special that I need to do with configuring these 2 pins?

This is what I have:

//SMBUS
ioport_configure_pin(SMBUS_SDA_E0_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH);
ioport_configure_pin(SMBUS_SCL_E1_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH);

I am getting a twi master interrupt but nothing showin on the pins.

Any ideas?

Thanks

Charles

Here is the code:

//=============================================================================================
//						SMBUS 
//=============================================================================================

#include "spi_master.h"
#include "compiler.h"
#include "conf_board.h"
#include "ioport.h"
#include "ioport_compat.h"
#include 
#include 
#include 
#include "wdt.h"
#include "twi_master_driver.h"
#include "twi_slave_driver.h"

/* Scheduler include files. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
#include "smart.h"
/* Hardware initialization */
#include "conf_board.h"
#include 
#include "sysclk.h"

/*! CPU speed 32MHz, BAUDRATE 100kHz and Baudrate Register Settings */
#define CPU_SPEED   32000000
#define BAUDRATE	100000
#define TWI_BAUDSETTING TWI_BAUD(CPU_SPEED, BAUDRATE)
#define SLAVE_ADDRESS 2


void TWIC_SlaveProcessData(void);

TWI_Master_t twiMaster;    /*!< TWI master module. */
TWI_Slave_t twiSlave;      /*!< TWI slave module. */

extern unsigned char SMBUS_msg_rdy = 0;
unsigned char SMBUS_bc = 0;

/*! Buffer with test data to send.*/
uint8_t sdBuf[20] = {'R', 0x01, 0x02, 0x03, 0x00, 0x00, 0x00};
uint8_t rxdBuf[20];

//==================================================================================================
void vSMBUS_Task( void *pvParameters )   //Wait for SMBUS messages
//==================================================================================================
{

	/* Initialize TWI master. */
	TWI_MasterInit(&twiMaster,&TWIC, TWI_MASTER_INTLVL_LO_gc, TWI_BAUDSETTING);

	/* Initialize TWI slave. */
	//TWI_SlaveInitializeDriver(&twiSlave, &TWIC, TWIC_SlaveProcessData);
	
	//TWI_SlaveInitializeModule(&twiSlave, SLAVE_ADDRESS, TWI_SLAVE_INTLVL_LO_gc);

	
	for( ;; )
	{
		TWI_MasterWriteRead(&twiMaster,1, &sdBuf,3,5);			//Send SMBUS message
		while (twiMaster.status != TWIM_STATUS_READY);			//Wait  for completed transaction
		
	
		//	We have a SMBUS message
		//	----------------------
	    if (SMBUS_msg_rdy == TRUE)
		{
			SMBUS_msg_rdy = FALSE;
			SMBUS_bc = 0;
		}	
		
		vTaskDelay(100/portTICK_RATE_MS);
		
	}
	
}	

//===================================================================================================
void TWIC_SlaveProcessData(void)
//===================================================================================================
{
	SMBUS_msg_rdy = FALSE;	
	
}	


//===================================================================================================
    ISR(TWIC_TWIM_vect)		//TWI Master Interrupt service
 //===================================================================================================
{
     TWI_MasterInterruptHandler(&twiMaster);
}

//===================================================================================================
ISR(TWIC_TWIS_vect)		//TWI Slave Interrupt service
//===================================================================================================
{
	TWI_SlaveInterruptHandler(&twiSlave);
}
	
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think I know what the problem is. The file provided by Atmel "iox128d3.h" does not have definition for the TWI of port E (TWIE). All the code above is for the TWI of port C (TWIC) and i did not realize that the hardware was laid out for pins on port E. In order to switch to port E I need to replace all the reference to TWIC to TWIE. The only problem that that I have now is I do not know the vector number for TWIE interrupt master & slave. I see that for TWIC it has vector 12 & 13. Anybody knows what vector number are assigned to TWIE?
Looking at the specification, I only see the interrupt base address for TWIC and TWIE (0x18 & 0x5a)

Thank you,

Charles

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The errata for the D3 says that TWIE is not available, hence there are no defines for it. Looks like there was a silicone bug.