Problems using TWIM0 on UC3A3

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

I used this code to initialize the TWIM0 unit on AVR32UC3A3256 device.
Sometimes in debug mode the code worked most times not!
If it worked I could see on my analyzer the communication protocol is correct without code changes.

There are 2 x 3K3 resistors connected between SDA SCL lines and vcc.

The software framework is 3.5.1

Is there anything wrong?

void twim_init (void)
{
	int8_t status;
	// SDA = PA25
	// SCL = PA26
	// Set TWIM options
	const twi_options_t TWIM_OPTIONS = {
		.pba_hz = 66000000,
		.speed = 50000,
		.chip = 0x51>>1,
		.smbus = false,
	};	
 
	const gpio_map_t TWIM_GPIO_MAP = {
		{AVR32_TWIMS0_TWD_0_0_PIN, AVR32_TWIMS0_TWD_0_0_FUNCTION},
		{AVR32_TWIMS0_TWCK_0_0_PIN, AVR32_TWIMS0_TWCK_0_0_FUNCTION}
	};
	
	gpio_enable_module(TWIM_GPIO_MAP,
	sizeof(TWIM_GPIO_MAP) / sizeof(TWIM_GPIO_MAP[0]));

	sysclk_enable_pba_module(SYSCLK_TWIM0);

	// Initialize as master.
	status = twim_master_init (TWIM, &TWIM_OPTIONS);
	// Check whether TARGET device is connected
	if (status == STATUS_OK) {
		// display test result to user
		print_dbg ("TWI SLAVE FIND :\tPASS\r\n");
	} else {
		// display test result to user
		print_dbg ("TWI CHIP FIND :\tFAILED\r\n");
	}
}
Last Edited: Mon. Jun 17, 2013 - 01:45 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The first twi_master_read() operation delivers an IO Error (0xFFFFFFFF) but there is no IO error!

void tsk_lsi331_setup(void)
{
	int8_t status;
twi_package_t  packet, packet_received;

	packet_received.chip = 0x51>>1;		// device address
	packet_received.addr[0] = 0x0F;		// mem sub address
	packet_received.addr[1] = 0x00;
	packet_received.addr[2] = 0x00;
	packet_received.addr_length = 1;	// sub Address length
	packet_received.buffer = (void*)twi_read_data;
	packet_received.length = 1;
	
	

		print_dbg ("LSI331 Reading data ...\r\n");
		if(twim_status())
		{
			// Read data from TARGET
			status = twi_master_read (TWIM, &packet_received);
		}