USI problems

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

I am using the following code on a tiny45 using the internal oscillator at 8mhz, but when I am scoping the waves, they are not coming out anything close to what I expect. I can't see any type of discernable start or end to each packet. I was able to see the transmission when I clocked it at 12mhz, but then when I modified the code to send out more than one character, I got the same result as I described above. For some reason, I can't get anything to work correctly now either. I pulled the code straight from the tiny45 datasheet for usi transmission. Any Ideas?

//************************************* #include **********************************
#include 
#include 
#include 

//************************************ prototypes *********************************
void init(void);
void time_loop(int onemicro);
void send();

//************************************ variables **********************************
unsigned char m;
unsigned char s_temp;
unsigned char temp;
unsigned char INIT1[14] PROGMEM = {'U','W'};

//*********************************** main program ********************************
int main (void)
{
	init();
	for(;;)
	{
		send();
	}
}

//*********************************************************************************
void send()
{
	USIDR = pgm_read_word(&INIT1[m]);
	asm volatile("nop");

	USICR = (1<<USIWM0) | (0<<USICS0) | (1<<USITC);
	USICR = (1<<USIWM0) | (0<<USICS0) | (1<<USITC) | (1<<USICLK);

	USICR = (1<<USIWM0) | (0<<USICS0) | (1<<USITC);
	USICR = (1<<USIWM0) | (0<<USICS0) | (1<<USITC) | (1<<USICLK);

	USICR = (1<<USIWM0) | (0<<USICS0) | (1<<USITC);
	USICR = (1<<USIWM0) | (0<<USICS0) | (1<<USITC) | (1<<USICLK);

	USICR = (1<<USIWM0) | (0<<USICS0) | (1<<USITC);
	USICR = (1<<USIWM0) | (0<<USICS0) | (1<<USITC) | (1<<USICLK);

	USICR = (1<<USIWM0) | (0<<USICS0) | (1<<USITC);
	USICR = (1<<USIWM0) | (0<<USICS0) | (1<<USITC) | (1<<USICLK);

	USICR = (1<<USIWM0) | (0<<USICS0) | (1<<USITC);
	USICR = (1<<USIWM0) | (0<<USICS0) | (1<<USITC) | (1<<USICLK);

	USICR = (1<<USIWM0) | (0<<USICS0) | (1<<USITC);
	USICR = (1<<USIWM0) | (0<<USICS0) | (1<<USITC) | (1<<USICLK);

	USICR = (1<<USIWM0) | (0<<USICS0) | (1<<USITC);
	USICR = (1<<USIWM0) | (0<<USICS0) | (1<<USITC) | (1<<USICLK);
}

//*********************************************************************************
void init(void)									//Initialization
{
												//  		 RESET,XTAL2,XTAL1, USCK, DO, 	DI
												// NA    NA	  PB5   PB4   PB3   PB2   PB1   PB0
												// I     I     I     I     I     O     O     I
	DDRB = 0x06;								// 0     0     0     0     0     1     1     0
	PORTB = 0x00;								// 0     0     0     0     0     0	   0	 0

	sei();	 									//global interrupt enable
}

//*********************************************************************************
void time_loop(int onemicro)					//Time loop => one loop = 1 us
{
	for(;onemicro > 0;onemicro--)
	{
		asm volatile ("nop");
		asm volatile ("nop");
		asm volatile ("nop");
		asm volatile ("nop");
		asm volatile ("nop");
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I can't see any type of discernable start or end to each packet.

I am not sure what you expect to see. The program as it stands only sends 'U' which is binary 01010101. The only thing you can see is the time between two sends (which comes from funtion call overhead + fetching the character + assigning USIDR + the 'nop').

  USIDR = pgm_read_word(&INIT1[m]); 

You should probably read a byte here not a word.

/Lars

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

The problem comes in when I try to send out more than just one character, for example if I were to try to send out U and V. When I am looking at the line with my logic analyzer, I cannot see each of the letters, just a jumble of waves. If I just send U, I am able to see the letter being repeated with time in between the characters. What I would like to be able to see is several characters that I can read from an array stored in PROGMEM, but I can't get them to work properly

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

Post the code if possible.

You could make a pin high during the send function (if there is an unused pin). This should allow you to see the extent of one character with the logic analyzer.
/Lars