Tiny25 Soft I2C

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

I am attempting to operate a shift register by writing a software serial routine but I am having repeatability issues with VERY simple routines.

I have hooked up my shift reg to push buttons on CLK and DATA and it operates fine, I can walk the data in no problem. I have LED's on all of the outputs to make sure everything is OK.

My very simple code is:

for(i=0;i<10;++i)
{
  PORTB &= ~(1<<4);
  PORTB |=  (1<<1);
  PORTB |=  (1<<4);
 
  PORTB &= ~(1<<4);
  PORTB &= ~(1<<1);
  PORTB |=  (1<<4); 
}

That simple code will put 0b01010101010101010101 into the shift reg one would think but no. I get random data all over the place, 5on, 3off, 20on, random. On the scope the port toggles look clean without ringing.

I put in a _delay_ms(10); after every bit operation and it becomes somewhat more predictable but 2 out of 10 is still random.

What the heck is going on? The input requirements of the shift reg are minimal and yet its like the tiny25 cannot drive it.

Shift register is a Supertex HV5812

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

I just hooked up my Bus Pirate in SPI mode and I can run the shift register perfectly so it is 100% a problem with the Tiny25V. Either it is having trouble driving the inputs or theirs some internal register making the IO flaky.

I will try a transistor totem pole tomorrow and see if its a issue driving the inputs but I suspect not as the scope shows a clean edges with only a 1V drop on logic high (Vcc=5V, Hi=4.2V, Lo=0V)

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

why not check with the scope what is goin on on the actual output pins of the controller in combination with clock and data and see if you can see what is going wrong.

also take a look at the produced compiler code to see if instructions are not optimized away.

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

Did you decouple the chips with 100nF caps ?

/Bingo

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

Hey,

I got it working, the problem was that due to the boost converter in the project it was raising ground potential to 0.875V and I just assumed gnd = 0V. I added 47uF and 0.1uF caps to the boost converters input to help fluctuations and that made my shift register logic run properly.

My scope is an old analog beast and im sure it needs a calibration pretty badly but its not worth the $200 it costs, I just use the 1kHz output at the front to adjust it to 'good enough'

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

I have started on using the Tiny25's USI in TWI mode by following Don Blake's code in this thread. Code compiles great but I had some confusion on addressing. It turns out the address you assign using init is not the same one as you use to R/W. Turns out the address is shifted left one and the LSB is the R/W toggle. (0x69<<1=0xD2) The bus pirate once again helped by sniffing out the proper addresses.

My little routine:

  // Init USI_TWI (I2C) with an address
  TWI_slaveAddress = 0x69;
  usiTwiSlaveInit(TWI_slaveAddress);

  // Put some data into the buffer
  usiTwiTransmitByte(0x01);
  usiTwiTransmitByte(0x08);
  usiTwiTransmitByte(0x10);
  usiTwiTransmitByte(0x80);
  
  for(;;)
  {
    if( usiTwiDataInReceiveBuffer() )
    {
      temp = usiTwiReceiveByte();
      usiTwiTransmitByte(0x11);
    }
  } 

I can read the info from the buffer but I cannot write anything to it.

I2C> (1)
Searching 7bit I2C address space. 
   Found devices at:0xD2(0x69 W) 0xD3(0x69 R)

I2C> [0xD3 r:4]
I2C START BIT
WRITE: 0xD3 ACK 
READ: 0x01  ACK 0x08  ACK 0x10  ACK 0x80  NACK
I2C STOP BIT


I2C> [0xD2 0x11 0x12 0x13 0x14]
I2C START BIT
WRITE: 0xD2 ACK 
WRITE: 0x11 ACK 
WRITE: 0x12 ACK 
WRITE: 0x13 ACK 
WRITE: 0x14 ACK 
I2C STOP BIT

I2C> [0xD3 r:4]
I2C START BIT
WRITE: 0xD3 ACK 
READ: 0x00  ACK 0x00  ACK 0x00  ACK 0x00  NACK
I2C STOP BIT

I am unsure how write as usually you send an address to write to on a slave device. My device is going to take the input and put it into an array then erase the buffer. I only need write mode.

What is the proper sequence to write data?