Xmega and MAX6633(Problem with TWI)

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

Good day.
I am trying to establish a connection between ATXmega32 and MAX6633. And faced with a problem.
It hangs in, most of all, I cycle a bit TWI_MASTER_WIF_bm expectations that it missed when setting up.
I used as a tightening resistors 4k7.

 

#define MAX_ADDR	0x80
#define MAX_WRITE	0x00
#define MAX_READ	0x01
#define MAX_Command 0x00

void TWIC_init(void)
{
	TWIC.CTRL = 0;
	TWIC.MASTER.BAUD = 0x23;						//8 MHz-> 100kHz
	TWIC.MASTER.CTRLA = TWI_MASTER_INTLVL_gm | TWI_MASTER_RIEN_bm | TWI_MASTER_WIEN_bm | TWI_MASTER_ENABLE_bm;
	TWIC.MASTER.CTRLB = 0;
	TWIC.MASTER.CTRLC = 0;
	TWIC.MASTER.STATUS = TWI_MASTER_RIF_bm | TWI_MASTER_WIF_bm | TWI_MASTER_ARBLOST_bm | TWI_MASTER_BUSERR_bm | TWI_MASTER_BUSSTATE0_bm;
}


void TWIC_Transiver()
{
    TWIC.MASTER.ADDR = MAX_ADDR | MAX_WRITE ;							// 0b10000000 
    while (!(TWIC.MASTER.STATUS & TWI_MASTER_WIF_bm));
    PORTC.OUTSET = PIN4_bm;	
    TWIC.MASTER.DATA = MAX_Command;										// 0b00000000
    while(!(TWIC.MASTER.STATUS & TWI_MASTER_WIF_bm));
	 
	TWIC.MASTER.ADDR = MAX_ADDR | MAX_READ ;							// 0b10000001
    while (!(TWIC.MASTER.STATUS & TWI_MASTER_WIF_bm));
     
    TWIC.MASTER.DATA = MAX_Command;										// 0b00000000
    while(!(TWIC.MASTER.STATUS & TWI_MASTER_WIF_bm));
    
	while(!(TWIC.MASTER.STATUS & TWI_MASTER_RIF_bm));
	MSB_temp = TWIC.MASTER.DATA;
	
	while(!(TWIC.MASTER.STATUS & TWI_MASTER_RIF_bm));
	LSB_temp = TWIC.MASTER.DATA;
	
    TWIC.MASTER.CTRLC = TWI_MASTER_ACKACT_bm | TWI_MASTER_CMD_STOP_gc;
}

And another question, whether there need any additional configuration TWI pins on the input and the output, or it is done in hardware?

Sorry for the bad translation...

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

Have a look at my code: https://github.com/kuro68k/xmega...

 

Do you have a logic analyzer? You can get one from eBay for a few Euros. It will help immensely if you can post a logic analyzer trace to show what output you are seeing, otherwise we will have to go over the code with a fine tooth comb and a lot of people don't have time.

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

I apologize for not having replied. I was away.

Partially changed its code:

void TWIC_init(void)
{
	TWIC.CTRL = 0;
	TWIC.MASTER.BAUD = 0x23;
	TWIC.MASTER.CTRLA = TWI_MASTER_ENABLE_bm;
	TWIC.MASTER.CTRLB = 0;
	TWIC.MASTER.CTRLC = 0;
	TWIC.MASTER.STATUS = TWI_MASTER_RIF_bm | TWI_MASTER_WIF_bm | TWI_MASTER_ARBLOST_bm | TWI_MASTER_BUSERR_bm | TWI_MASTER_BUSSTATE0_bm;
}

void TWIC_Transiver()
{
	LCD_init.OUTTGL = PIN4_bm;										// Led
    TWIC.MASTER.ADDR = MAX_ADDR | MAX_WRITE ;						// 0b10000000 
    while (!(TWIC.MASTER.STATUS & TWI_MASTER_WIF_bm));
    TWIC.MASTER.DATA = MAX_Command;									// 0b00000000
    while(!(TWIC.MASTER.STATUS & TWI_MASTER_WIF_bm));
	
	TWIC.MASTER.ADDR = MAX_ADDR | MAX_READ ;						// 0b10000001
    //while (!(TWIC.MASTER.STATUS & TWI_MASTER_WIF_bm));

	while(!(TWIC.MASTER.STATUS & TWI_MASTER_RIF_bm));
	MSB_temp = TWIC.MASTER.DATA;
	
	//while(!(TWIC.MASTER.STATUS & TWI_MASTER_RIF_bm));
	//LSB_temp = TWIC.MASTER.DATA;
	
    TWIC.MASTER.CTRLC = TWI_MASTER_ACKACT_bm | TWI_MASTER_CMD_STOP_gc;
}

 

 

According to the Logic Analyzer, address and read command are transferred correctly. Then the MAX6633 starts to transmit information to me. High byte I get correctly when trying to get younger, the program hangs = (

//while(!(TWIC.MASTER.STATUS & TWI_MASTER_RIF_bm));
//LSB_temp = TWIC.MASTER.DATA;

And I was plagued by doubts about the correctness of my actions. Because I tried to warm the chip, and Logic Analyzer response is sent unchanged.

 

Sorry for the bad translation...