Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
topazx2
PostPosted: Jun 30, 2007 - 12:16 AM
Wannabe


Joined: Sep 05, 2004
Posts: 61
Location: Oregon

Hi,
This post is intended for Don Blake, but we thought others might be able to contribute/benefit from it as well.

I am trying to get my ATtiny45 Slave device using the USI-TWI interface to send data back to an ATmega88 Master device using standard TWI.
I've had plenty of success sending commands to the ATtiny, but getting it to return anything has proven difficult to say the least.

I was using the IAR code from AVR312 in a demo version of IAR, but I found Don's conversion of that code for Atmels GCC and would much rather use that since I'm familiar with AVRstudio and the STK500.

My question is, has anyone had any success getting a slave to return data over the USI-TWI interface and if so, would you care to share that code or at least the experience with a novice experimenter?
Also, for Don, can I use the AVR312 main.c with your converted code?

Thanks, Dan Gates

_________________
There are 10 types of people in this world,
those who understand binary and those who do not.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
donblake
PostPosted: Jun 30, 2007 - 01:28 AM
Posting Freak


Joined: Jan 03, 2004
Posts: 1637
Location: Apalachin, NY, USA

topazx2 wrote:
My question is, has anyone had any success getting a slave to return data over the USI-TWI interface and if so, would you care to share that code or at least the experience with a novice experimenter?
Dan, I only have one application that uses the USI-TWI interface on an ATtiny2313. It does not read from the slave device. I've never even tried reading from the slave. When I get a chance, I'll look over the code and see if there's anything obvious.

I don't think I ever would have gotten this code working without my oscilloscope. Have you used an oscilloscope to see what's going on during a slave read?

Are you calling usiTwiTransmitByte to place data in the transmission buffer before the master tries to read from the slave? What do you see happening on the master side during a slave read?

BTW - the code that Dan is refereeing to is an attachment in my post of 16 April 2007 in this thread.

topazx2 wrote:
Also, for Don, can I use the AVR312 main.c with your converted code?
I've never even looked at main.c before just a little bit ago. Off hand, I don't see why not as long as you change the function names to match my implementation.

Don
 
 View user's profile Send private message  
Reply with quote Back to top
donblake
PostPosted: Jul 01, 2007 - 01:05 AM
Posting Freak


Joined: Jan 03, 2004
Posts: 1637
Location: Apalachin, NY, USA

Dan, another question: what speed are you running the ATtiny45 at? Also, are you trying to run the I2C bus at 100 KHz or 400 KHz?

I'm not familiar with the ATtiny45 - the ATtiny2313 defaults to 1 MHz (8 MHz internal RC oscillator with divide clock by 8). I can't find the reference, but IIRC, 1 MHz is not fast enough for a 100 KHz I2C bus. I'm running my ATtiny2313 at 4 MHz.

Don
 
 View user's profile Send private message  
Reply with quote Back to top
topazx2
PostPosted: Jul 03, 2007 - 06:40 PM
Wannabe


Joined: Sep 05, 2004
Posts: 61
Location: Oregon

I have a debug routine that shows where any errors occur during communication, plus I have a logic capture device that we created to be able to see exactly what's going on during communication.
I can see that during a master write, everything goes as expected without a hitch. However, in a master read routine, everything does what I expect accept that the returned data is all zeros rather than the expected value of 0x0F that I've placed in the USIDR.

I have not yet tried using your version of the Slave driver, so I will attempt that today and get back to you.

BTW, I've got the tiny45 set at 20Mhz using the internal PLL clock. I do understand that the slave device has to be running at a minimum of 10 times the I2C bus, but even at the 20Mhz I still have not been able to get speeds of 100k on the bus. The best I can do and still get reliable results is ~75k. Good enough for now.

_________________
There are 10 types of people in this world,
those who understand binary and those who do not.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
topazx2
PostPosted: Jul 03, 2007 - 10:34 PM
Wannabe


Joined: Sep 05, 2004
Posts: 61
Location: Oregon

Ok, here's the status.
I've attempted communications using Don's code and still no success. I am no longer getting a start condition ack as I was with my old code.
So now I'm curious as to why I get a response and am able to at least send data using the old slave code (same master code), but not able to even get a start condition when using the new slave code.

I suppose there's a chance that something in the master code is wacky, is there any chance of seeing a sample of the master code you use to communicate with your slave device?

-Dan

_________________
There are 10 types of people in this world,
those who understand binary and those who do not.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
donblake
PostPosted: Jul 03, 2007 - 11:08 PM
Posting Freak


Joined: Jan 03, 2004
Posts: 1637
Location: Apalachin, NY, USA

topazx2 wrote:
I am no longer getting a start condition ack as I was with my old code.
Are you using the AVR312 main.c? Are you including <avr/io.h> and <avr/interrupt.h> and did you change __enable_interrupt() to sei( );?

Also, if you're using the AVR312 main.c, I'd suggest removing the code that writes to DDRB and PORTB.

topazx2 wrote:
I suppose there's a chance that something in the master code is wacky, is there any chance of seeing a sample of the master code you use to communicate with your slave device?

Sure. I've added my master utility code here. I didn't include a main.c because it's somewhat involved. Basically, main needs to enable global interrupts via sei( ), call twiInit and call twiWrite.

I've started to put together a simple test case where the master does a slave write followed by a slave read. If you're still stuck, I'll continue working on it and see if I can figure out what's going on.

Don
 
 View user's profile Send private message  
Reply with quote Back to top
topazx2
PostPosted: Jul 04, 2007 - 12:46 AM
Wannabe


Joined: Sep 05, 2004
Posts: 61
Location: Oregon

Don,
I was able to get my master code to send data to your slave code. I'm now working on getting a response which eludes me in both versions of the slave code.

I would certainly appreciate any time you're willing to devote to this, you may see something that I'm just not seeing.

BTW, Yes on all above cautions. Smile I've attached a copy of the main.c code I've been working with (receives but doesn't reply)

-Dan

_________________
There are 10 types of people in this world,
those who understand binary and those who do not.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
donblake
PostPosted: Jul 04, 2007 - 04:08 AM
Posting Freak


Joined: Jan 03, 2004
Posts: 1637
Location: Apalachin, NY, USA

topazx2 wrote:
I would certainly appreciate any time you're willing to devote to this, you may see something that I'm just not seeing.
I have the sample program working - using an ATmega88 as the master and an ATtiny2313 as a slave. I'm able to transmit data to the slave and read back the echoed data. But . . .

topazx2 wrote:
I've attached a copy of the main.c code I've been working with (receives but doesn't reply)
I see the following problem in main.c:
Code:
if(usiTwiDataInReceiveBuffer())
{
  temp = usiTwiReceiveByte();

  switch (temp)
  {
    case 1: led(LED1, 1); break;
    case 2: led(LED2, 1); break;
    case 3: led(LED3, 1); break;

    usiTwiTransmitByte(distance);
  }
 //       usiTwiTransmitByte(distance);
 }
usiTwiTransmitByte will never be called. Your switch statement has 3-cases which all end in break and no default: case. The usiTwiTransmitByte within the switch statement is dead code; it'll never be executed. As a matter of fact, the switch statement does nothing.

Edit: my statement about the switch statement doing nothing is incorrect - the led( ) function is being called.

I've attached my working Slave main.c which echoes all received data (that is, if the master reads back as many bytes as are written within the limits of the Rx and Tx buffers).

Don
 
 View user's profile Send private message  
Reply with quote Back to top
topazx2
PostPosted: Jul 04, 2007 - 05:00 PM
Wannabe


Joined: Sep 05, 2004
Posts: 61
Location: Oregon

Don,
Actually the code I sent was only depicting the working receive code, I don't use the LED switch commands in the code I'm trying to get to return data.
Sorry for the confusion I should have commented the usiTwiTransmitByte out before sending.

I am going to take a look at what you've posted right now and get back to you in a few. Thanks for taking the time and happy 4th!

-Dan

_________________
There are 10 types of people in this world,
those who understand binary and those who do not.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
donblake
PostPosted: Jul 04, 2007 - 11:39 PM
Posting Freak


Joined: Jan 03, 2004
Posts: 1637
Location: Apalachin, NY, USA

topazx2 wrote:
I am going to take a look at what you've posted right now and get back to you in a few. Thanks for taking the time and happy 4th!
Not at all. Having struggled with I2C on numerous occasions, I'm always anxious to help.

Happy 4th to you too. Hope the weather is better there. We haven't had rain in what seems like forever and it's been raining all day with a high temperature of 62 degrees.

Don
 
 View user's profile Send private message  
Reply with quote Back to top
topazx2
PostPosted: Jul 11, 2007 - 09:48 PM
Wannabe


Joined: Sep 05, 2004
Posts: 61
Location: Oregon

Well, thanks to Don Blake's efforts in translating ATMELs IAR version of the USI TWI code to a more useful AVR GCC version, I am happy to report that I can successfully transmit and receive from an ATmega88 to an ATtiny45 using I2C protocol. I plan to post a working version of the code once I clean it up a bit and document it all a little better.

Don, I never did get a chance to look at that last bit of code you sent since I got it all working right after writing you the last time. I have downloaded it for future reference though, thanks!

-Dan

_________________
There are 10 types of people in this world,
those who understand binary and those who do not.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
topazx2
PostPosted: Jul 11, 2007 - 10:37 PM
Wannabe


Joined: Sep 05, 2004
Posts: 61
Location: Oregon

Don,
I noticed that your location shows Apalachin, NY. That reminded me of something I saw recently.

Due to the new code of conduct dictated by politically correctness, those who live in the hills of Kentucky and Tennessee shall no longer be referred to as Hill Billy's, but shall now be known as Apalachin Americans.

-Dan

_________________
There are 10 types of people in this world,
those who understand binary and those who do not.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
donblake
PostPosted: Jul 12, 2007 - 03:46 AM
Posting Freak


Joined: Jan 03, 2004
Posts: 1637
Location: Apalachin, NY, USA

topazx2 wrote:
Well, thanks to Don Blake's efforts in translating ATMELs IAR version of the USI TWI code to a more useful AVR GCC version, I am happy to report that I can successfully transmit and receive from an ATmega88 to an ATtiny45 using I2C protocol.
Dan, that's good news!
topazx2 wrote:
Due to the new code of conduct dictated by politically correctness, those who live in the hills of Kentucky and Tennessee shall no longer be referred to as Hill Billy's, but shall now be known as Apalachin Americans.
Cute. Actually, Apalachin (small town in Central New York) is pronounced differently than Appalachian (as in mountains of Eastern North America). However, having said that, I probably am a hillbilly.

Don
 
 View user's profile Send private message  
Reply with quote Back to top
skogsvargen
PostPosted: Aug 01, 2007 - 03:37 PM
Wannabe


Joined: Nov 18, 2005
Posts: 89


Hi all,
I am trying to do the same thing as you, and the slavs code seems straight foreward, but how do i interface the slave code on the master side?

I2c master protocols typically start by sending an adress byte and then writing a data byte, starting and stopping etc.

Can someone share their master code that works with this slave code?

regards

Magnus
 
 View user's profile Send private message  
Reply with quote Back to top
donblake
PostPosted: Aug 02, 2007 - 04:31 AM
Posting Freak


Joined: Jan 03, 2004
Posts: 1637
Location: Apalachin, NY, USA

skogsvargen wrote:
Can someone share their master code that works with this slave code?
I posted my master utility code in this thread back on 03 July.

Don
 
 View user's profile Send private message  
Reply with quote Back to top
skogsvargen
PostPosted: Aug 02, 2007 - 07:41 AM
Wannabe


Joined: Nov 18, 2005
Posts: 89


Don,
I found the master I2C library, but I really need some instructions how to use them together with the slave example that echoes bytes sent from the slave.

/Magnus
 
 View user's profile Send private message  
Reply with quote Back to top
donblake
PostPosted: Aug 03, 2007 - 04:43 AM
Posting Freak


Joined: Jan 03, 2004
Posts: 1637
Location: Apalachin, NY, USA

skogsvargen wrote:
I found the master I2C library, but I really need some instructions how to use them together with the slave example that echoes bytes sent from the slave.
Ah, okay, here's an example master source file I've used. It writes the echoed data to an LCD if NOLCD is not defined.

You'll probably need to change the #undef NOLCD to #define NOLCD.

Don
 
 View user's profile Send private message  
Reply with quote Back to top
topazx2
PostPosted: Sep 25, 2007 - 06:02 PM
Wannabe


Joined: Sep 05, 2004
Posts: 61
Location: Oregon

Ok, here's some sample code for using the ATtiny45 as a slave device. The slave code assumes you have an analog sensor of some sort connected to pin3 (PB4) of the tiny45.
The tiny45 is configured for analog reference of 2.5v and uses the USI as a TWI (I2C) interface.

The master device is an ATmega88 and assumes that you have a 16x2 LCD connected in four bit mode. The LCD provides error feedback if selected or prints the analog data if no errors occur.
The current slave address is 0x26. This can be changed, but requires changing in both the slave and the master.

The master code is pretty vague since my focus was on the slave side, but everything works.

-Dan Gates

_________________
There are 10 types of people in this world,
those who understand binary and those who do not.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
topazx2
PostPosted: Sep 25, 2007 - 06:04 PM
Wannabe


Joined: Sep 05, 2004
Posts: 61
Location: Oregon

Some of you may not be able to use an RAR compressed file, so here's the zipped version.

-Dan Gates

_________________
There are 10 types of people in this world,
those who understand binary and those who do not.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
eshani
PostPosted: Dec 13, 2007 - 06:30 PM
Newbie


Joined: Dec 13, 2007
Posts: 10


Hi,

I was just going through your posts and need your suggestions and help for two wire interface using ATTiny24 and At24C01B.

In my case Attiny24 is Master and EEPROM(24C01) is slave.

I am using internal clock of 1MHz and generating the clock for TWI by software storbe.

I can generate the clock and also can send data if I avoid genrating ststrt conditon. I hv observed the clk and data on oscilloscope but I am not able to generate start condition. Also I dont get any acknowlegement from Slave. If I am on the verge to generate start condition my clock stops.

I am attaching the code here.
Please help.

Thanks,
Eshani

quote="donblake"]
skogsvargen wrote:
Can someone share their master code that works with this slave code?
I posted my master utility code in this thread back on 03 July.

Don[/quote]
 
 View user's profile Send private message  
Reply with quote Back to top
topazx2
PostPosted: Jul 15, 2008 - 10:08 AM
Wannabe


Joined: Sep 05, 2004
Posts: 61
Location: Oregon

Eshani,
There are two acceptable ways to address a device, one is the Phillips standard and the other is Atmel's twi standard. Phillips expects the address to come across the line as is I.E. 0x2C is 0x2C on the transmission line. The twi standard actually shifts the address bit on place to the left for transmission, so 0x2C becomes 0x4C over the bus. There is a really good reason why Atmel does the shifting, it makes the transmit and receive bit easier to deal with.
Anyway, to cut this short, try shifting the address bits to access the EEPROM, most eeprom chips use the Phillips standard.

_________________
There are 10 types of people in this world,
those who understand binary and those who do not.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
topazx2
PostPosted: Jul 15, 2008 - 10:12 AM
Wannabe


Joined: Sep 05, 2004
Posts: 61
Location: Oregon

If your slave devices address is 0x4C, then you need to use address 0x2C in your code to access it. The Atmel code will shift the bits to the left so your EEPROM sees its own address of 0x4C.

_________________
There are 10 types of people in this world,
those who understand binary and those who do not.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
wmileski
PostPosted: Jul 28, 2008 - 10:34 PM
Newbie


Joined: Jul 21, 2008
Posts: 2


Hi,
I am a newbie trying to make an I2C slave of the AtMega169V. Thanks for the port to avr-gcc. I however, cannot get the AVR to ack a start condition sent by a master. The master is part of a working 100kHz I2C setup with several other peripherals. I am using the STK500 and STK502. The 169V is running at 8MHz (verified on scope). The master sends a read to 0x75 that looks good on the scope, which is not ack'd, and of course the master sends a stop.

I am using I2C_Slave.c with sei(), but it seems neither the ISR(USI_OVERFLOW_VECTOR) nor ISR(USI_START_VECTOR) are being called. I tested this later by setting PORTD (and an LED) from inside each, at the top, followed by an immediate return. Hope this is a valid test.

I am assuming 0x75 does not need a left shift, since the master really is sending an 0x75.

It looks like there is no device-specific code in the sample slave code, and no typos in the defines for the ATmega169.

Any hints for an engineer initially struggling to be productive in the embedded world..

Bill
 
 View user's profile Send private message  
Reply with quote Back to top
wmileski
PostPosted: Jul 28, 2008 - 11:43 PM
Newbie


Joined: Jul 21, 2008
Posts: 2


..continued..

After a couple days of frustration, got data from my master to the AVRmega169 slave, only minutes after posting for help.

Compiling with -O0 --> no ack, no transaction
Compiling with -Os --> ack, good write transaction

Sorry to spin anybody up,

Bill
 
 View user's profile Send private message  
Reply with quote Back to top
devinur
PostPosted: Jul 15, 2009 - 05:20 AM
Newbie


Joined: Jul 14, 2009
Posts: 6


"The current slave address is 0x26. This can be changed, but requires changing in both the slave and the master. "

can u be more specific about this,
i`m using atmega8 as a slave and atmega32 as a master, still confused about the address in the slave
(1 master and 4 slave, i need to give different address to each slave)

thanks
 
 View user's profile Send private message  
Reply with quote Back to top
devinur
PostPosted: Jul 15, 2009 - 06:01 AM
Newbie


Joined: Jul 14, 2009
Posts: 6


i don`t have any library about "usiTwiSlaveInit"
can u explain this

thanks
 
 View user's profile Send private message  
Reply with quote Back to top
devinur
PostPosted: Jul 15, 2009 - 06:06 AM
Newbie


Joined: Jul 14, 2009
Posts: 6


where i have to put address (0x26 in your example) ?
in register?

i`m using codevisionAvr
 
 View user's profile Send private message  
Reply with quote Back to top
donpsycho
PostPosted: Sep 05, 2009 - 03:11 PM
Newbie


Joined: Sep 05, 2009
Posts: 1


Hi, i am new to AVR and i thought about using an ATmega8 (8Mhz) as an USI Master and an ATtiny2313 (8Mhz) as an USI Slave. While browsing through the internet i stubbled accross don's libs, "twi" for the master and "usiTwiSlave" for the Slave. I tried using 2 of the examples.

My Slave Code looks like this:
Code:

#include <avr/io.h>
#include <avr/interrupt.h>
#include "usiTwiSlave.h"

// TWI Slave defines
#define TWI_SLA 0x07  // Slave Address
int main(void)
    {
    unsigned char temp = 0;
    DDRA = 0x07; // set ddra as output

    // Own TWI slave address
    usiTwiSlaveInit(TWI_SLA);
    sei( );

    for (;;)
   {
   if (usiTwiDataInReceiveBuffer())
       {
       temp = usiTwiReceiveByte();
       }
   PORTA = temp; // activate a few leds to visualize the data
   }
    return 0;
    }


And my Master Code like this:
Code:

//Includes
#include <avr/io.h>
#include <avr/interrupt.h>
#include "twi.c"

//defines
#define Slave 0x07

// Globales Variables
uint8_t data;

//main
int main(void)
    {
    DDRB = 0xff; // Port B as Output
    PORTB |= (1 << PB4);

    data = 0x02; //initilize data
    twiInit(10); //init twi
    sei( );

    while (1)
   {
   //twiWrite(Slave,&data,1);
   if (twiStart(Slave, TW_WRITE)) // 0 = error , non 0 = ok
       {
       PORTB &= ~(1 << PB4);
       PORTB |= (1 << PB1);
       twiStop();
       PORTB &= ~(1 << PB1);
       }
   else
       {
       PORTB &= ~(1 << PB4);
       PORTB |= (1 << PB2);
       twiWriteBytes(&data, 1);
       twiStop();
       PORTB &= ~(1 << PB2);
       }
   }
    return 0;
    }

The Code looks like this because the controller always hangs up at twiStart, twiStop ... i guess it must be the

( TWCR & ( 1 << TWINT )

the weird thing is following:
if i touch the SCL pin with my hand or a screw driver or something like that it goes into the else case and with 95% sends the right data... the right leds on the attiny start glowing. But sometimes if i touch it again it jumps into the if case and is than stuck there forever.

i guess the tiny has to give some sort of feedback.

Also touching the SCL with VCC (+ 5V) or GND does not work.

I guess , the slave USI will pull SCL low when a start condition is detected is not working proberly but i cant imagine that the libary is wrong. So is there some stupid mistake i made ?

Thanks for your answers
 
 View user's profile Send private message  
Reply with quote Back to top
topazx2
PostPosted: Sep 30, 2009 - 08:00 PM
Wannabe


Joined: Sep 05, 2004
Posts: 61
Location: Oregon

devinur wrote:
i don`t have any library about "usiTwiSlaveInit"
can u explain this

thanks


You are not using any devices that require USI-TWI, both the Mega8 and the Mega32 use the traditional TWI, not the USI-TWI. This forum topic is not for you, this topic is specifically for those using an AVR device that only have a USI-TWI and all the code here is for use in AVR Studio with the GNU GCC tool chain, not codevision.

_________________
There are 10 types of people in this world,
those who understand binary and those who do not.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
topazx2
PostPosted: Sep 30, 2009 - 08:03 PM
Wannabe


Joined: Sep 05, 2004
Posts: 61
Location: Oregon

donpsycho wrote:

I guess , the slave USI will pull SCL low when a start condition is detected is not working proberly but i cant imagine that the libary is wrong. So is there some stupid mistake i made ?

Thanks for your answers



Do you have external pull-up resistors on the SCL and SDA lines? You cannot use internal Pull-ups for I2C.

_________________
There are 10 types of people in this world,
those who understand binary and those who do not.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
atdodd
PostPosted: Jan 04, 2010 - 05:12 AM
Newbie


Joined: Jan 24, 2002
Posts: 6
Location: Owego, NY

Dan and Don,
Thank you for the example code. I'm using it to implement an I2C-addressable RGB LED using a Tiny25. Once I clean up a few more things I'll be posting it here, I already have a thread going elsewhere but I just realized I need to make a change to my source archive and repost it. (All of my C source files reference the GPL but I forgot to actually include a copy of the GPL itself, oops!)

It's a small world that the I2C library I'm using was written by someone in the next town over (I am in Owego, I need to update my profile), and I'm guessing highly likely retired from the same company I'm working for now. Smile
 
 View user's profile Send private message  
Reply with quote Back to top
Berend
PostPosted: May 06, 2010 - 03:25 PM
Newbie


Joined: Sep 21, 2004
Posts: 1


Hello everyone,

I'm trying to get to attiny2313's to communicate through the usi twi. In my setup, the master tries to read out a certain value from the slave on a regular basis (for those who are interested: the slave is reading out 8 touch sensors and processes these in such a way you get a sort of fader).

The problem i came across was the library did not include a function to check if the transmitbuffer is empty so I could do with a single byte buffer, and still don't lose any information. So I said to myself: be brave and put the function in yourself. I did, and it works so i thought it'd be usefull for everyone to share the updated library with you.

The added function is called (analogous to the usiTwiDataInReceiveBuffer)
Code:
usiTwiDataInTransmitBuffer()


It returns 1 if there is data in the buffer and a zero otherwise.

Second point is: it seems everyone in this topic has used a non usi master, so I was wondering if anyone already converted the atmel code for the master too? After my succes in altering a library I feel like I can handle the world so I think I could do it myself. Then again it would be a waste of time if somebody else already did it.

Cheers,

Berend
 
 View user's profile Send private message  
Reply with quote Back to top
hng07
PostPosted: Dec 10, 2010 - 12:50 AM
Newbie


Joined: Jan 30, 2008
Posts: 2


Why can't I open the Code for sharing.zip? When I saved it, it always saved in index.php and When I open it directly, it displayed strange characters that I can't read. How do I save the file in *.zip extension?
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Dec 10, 2010 - 09:52 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62296
Location: (using avr-gcc in) Finchingfield, Essex, England

If you find that a downloaded file is called index.php then just rename it to the name you thought it should have been (with the correct extension) and then it should work. So if you download foo.rar and it is named index.php then just rename it back to foo.rar and your WinRar program should be able to open it.

Moderator.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
hng07
PostPosted: Dec 10, 2010 - 11:37 PM
Newbie


Joined: Jan 30, 2008
Posts: 2


Thank you. It worked.
 
 View user's profile Send private message  
Reply with quote Back to top
norien
PostPosted: Mar 09, 2011 - 08:25 PM
Rookie


Joined: Dec 09, 2008
Posts: 39
Location: Hungary

Thank Don, for the usitwislave.
It happened to be a great help to me. I need to use it in a tiny2313 slave, where the master (mega644) initiates a Write-Restart-Read sequence of single bytes.

At times I found the slave stuck in a state pulling SDA to L, thus blocking I2C. (It was seen by the master as arbitration lost - 0x38.) It seems, that in a rapid Write-Restart-Read the transmit buffer may stay empty, making USI_SLAVE_SEND_DATA return without releasing SDA.

I added a SET_USI_TO_READ_ACK - which should set SDA free. It started to work, but I'd appreciate anybody having a look at it.

Code:
   case USI_SLAVE_SEND_DATA:
      // Get data from Buffer
      if ( txHead != txTail )
      {
         txTail = ( txTail + 1 ) & TWI_TX_BUFFER_MASK;
        USIDR = txBuf[ txTail ];
      }
      else
      {
        // the buffer is empty
        SET_USI_TO_READ_ACK( );
        SET_USI_TO_TWI_START_CONDITION_MODE( );
        return;
      } // end if
      overflowState = USI_SLAVE_REQUEST_REPLY_FROM_SEND_DATA;
      SET_USI_TO_SEND_DATA( );
      break;

 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
trunet
PostPosted: Jul 02, 2011 - 03:53 AM
Newbie


Joined: Jul 01, 2011
Posts: 3


Hi,

First post on this forum, I'll introduce myself. My name is Wagner Sartori Junior, I'm from Brazil.

I'm trying to communicate an arduino uno as master using Wire library to a attiny2313 running with a 8Mhz external crystal. My fuses are set to LOW 0xff and HIGH 0x9f.

I plugged my Logic Analyzer on I2C bus and I can see my arduino sending SCL clock(100Khz) with read request on SDA to slave address but attiny does not answer anything. I'm lost. Three days and I'm feeling like a looser lol.

Arduino UNO(I2C master):
Code:

#include <Wire.h>

void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
  Serial.println("Initializing");
}

void loop()
{
  Wire.beginTransmission(0x26);
  Wire.send(120);
  Wire.endTransmission();
 
  Wire.requestFrom(0x26, 1);    // request 6 bytes from slave device #2

  while(Wire.available())    // slave may send less than requested
  {
    char c = Wire.receive(); // receive a byte as character
    Serial.print("Received:");
    Serial.println(c);         // print the character
  }

  delay(500);
}


attiny2313(I2C slave):
Code:

#include <avr/io.h>
#include <avr/interrupt.h>
extern "C"
{
        #include "usiTwiSlave.h"
}

int main(void)
{
   unsigned char slaveAddress, temp;

        sei(); // enable interupts

   slaveAddress = 0x26;
        usiTwiSlaveInit(slaveAddress);

   for(;;)
        {
      if(usiTwiDataInReceiveBuffer())
          {
          temp = usiTwiReceiveByte();
         usiTwiTransmitByte(120);
      }
      asm volatile ("NOP" ::);
   }
}
 
 View user's profile Send private message  
Reply with quote Back to top
trunet
PostPosted: Jul 02, 2011 - 06:45 AM
Newbie


Joined: Jul 01, 2011
Posts: 3


Success!!!

I figured out by myself that if attiny2313 is turned on BEFORE arduino, the I2C bus does not works.

Driving reset pin on attiny2313 from arduino low for some milliseconds, comes I2C bus works.
 
 View user's profile Send private message  
Reply with quote Back to top
trunet
PostPosted: Jul 03, 2011 - 05:40 AM
Newbie


Joined: Jul 01, 2011
Posts: 3


trunet wrote:

I figured out by myself that if attiny2313 is turned on BEFORE arduino, the I2C bus does not works.


If somebody is having the same problem, "Coding Badly" on arduino forum told me about BOD(Brown-out detection). I set fuses to FUSE_L = 0xff and FUSE_H = 0x99(BOD 4.3V) and now it's working perfectly without glitches.

Future reference:
http://arduino.cc/forum/index.php/topic,65381.0.html
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits