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
Lennart
PostPosted: Apr 10, 2007 - 11:43 AM
Raving lunatic


Joined: Oct 29, 2006
Posts: 2758
Location: Sweden

TWI hardware is limited to 400 Kbps so if you want 1-2 Mbps this is not an option...
 
 View user's profile Send private message  
Reply with quote Back to top
donblake
PostPosted: Apr 11, 2007 - 02:45 AM
Posting Freak


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

ZachSt wrote:
If you could post that, it would be great. I'm working on a similar project now. I have one master microcontroller, which I want to speak to three slave ones separately depending on the address. Right now I use an 8-bit bus, 3 address bits, and 2 control bits for a hand-shake, before realizing that TWI is probably the way to go.
I've tried several times to add this code as an attachment - a small zip file. I've tried it from both Firefox an MS IE. It seems like attachments are broken.

Don
 
 View user's profile Send private message  
Reply with quote Back to top
gedex
PostPosted: Apr 13, 2007 - 07:38 PM
Newbie


Joined: Feb 21, 2007
Posts: 3


thx for all recommendations.
i've decided to use UART, since it's easier to me (coz my project is near to deadline).
But if i've free time, i'll try TWI & SPI.
 
 View user's profile Send private message  
Reply with quote Back to top
donblake
PostPosted: Apr 17, 2007 - 05:11 AM
Posting Freak


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

donblake wrote:
I've tried several times to add this code as an attachment - a small zip file. I've tried it from both Firefox an MS IE. It seems like attachments are broken.
Hey - attachments are now working!
donblake wrote:
FWIW, I just got slave TWI (I2C) working on a ATTiny2313 using USI. It's based on Atmel's AVR312 Application Note. I ported the code to WINAVR GCC, did some cleanup and fixed several errors. If anyone's interested, I can make it available.

Here it is. I've tested slave receive but not slave transmit. Use at your own risk. Enjoy.

Don

[edit]
Code update: fixed ACK of slave address on a read.
 
 View user's profile Send private message  
Reply with quote Back to top
xchip
PostPosted: Aug 02, 2009 - 09:12 PM
Wannabe


Joined: Aug 25, 2005
Posts: 73


will that work with an at90s2313?

Thanks!
 
 View user's profile Send private message  
Reply with quote Back to top
Simonetta
PostPosted: Aug 02, 2009 - 10:36 PM
Resident


Joined: Mar 12, 2003
Posts: 996
Location: Portland, Oregon USA

Try a parallel version of I2C.

Use 8 bits for the data and the two remaining bits for handshaking signals. Start with one AVR as 'master' and one as 'slave' Set the eight port bits used as the data byte on the master as all outputs. Turn on the pull up resistors and set the master's two handshake bits as inputs. They will pull to logic high.
Start with the ten port bits on the slave as all inputs. Put a data byte on the master's data eight-bit data port pins. Make the master's NewDataReady handshake bit be an output and make it logic low. This signals to the slave that there is new data available. The slave reads the 8 data bits as a single input instruction, puts the data in SRAM or processes it. Then it makes the other handshake line an output and pulls it low.
The master sees the low from the slave and makes its active handshake line back into an input. It is pulled high by the internal resistor. The slave sees the master's active handshake line go high and returns its handshake line to an input, which makes it high. The master sees that the slave's handshake is high and puts the next byte onto the data lines. Then starts the process over.

Is this a bidirectional data transfer between the two AVRs? If so then maybe a standard SPI would be better, or even standard AVR I2C (TWI).

How fast is fast data transfer? Are you sending data in fixed length bursts? Or is the receiving AVR doing processing on each byte as it is received?
 
 View user's profile Send private message  
Reply with quote Back to top
david.prentice
PostPosted: Aug 02, 2009 - 10:57 PM
10k+ Postman


Joined: Feb 12, 2005
Posts: 16544
Location: Wormshill, England

xchip wrote:
will that work with an at90s2313?

Thanks!


I assume you are asking about Don Blake's USI_TWI code.

This will not work with the obsolete AT90S2313.
It will work with the current ATtiny2313.

David.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
xchip
PostPosted: Aug 03, 2009 - 10:34 AM
Wannabe


Joined: Aug 25, 2005
Posts: 73


ok thank you!!
 
 View user's profile Send private message  
Reply with quote Back to top
sasquach_dm
PostPosted: Oct 19, 2009 - 11:55 PM
Newbie


Joined: Sep 27, 2004
Posts: 3
Location: Alberta, Canada

just wondering has any1 tested don's code to transmit date from the slave
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
lineage2202
PostPosted: Feb 02, 2010 - 10:59 AM
Newbie


Joined: Feb 02, 2010
Posts: 3


has anybody implemented a 2-wire SPI in a PIC16F877A or in any microcontroller as the master?need some info for this because my slave IC which is an energy IC is configured as 2 wire SPI..all i need is to supply serial clock from the PIC to the slave so that i can get the data..the data comes from the slave..

is it possible that a PIC can be configured as 2 wire SPI using only the SCK and SDI pin?will the PIC(master) can still supply a serial clock if it is configured as 2 wire SPI?
 
 View user's profile Send private message  
Reply with quote Back to top
david.prentice
PostPosted: Feb 02, 2010 - 12:14 PM
10k+ Postman


Joined: Feb 12, 2005
Posts: 16544
Location: Wormshill, England

Please describe exactly what you want to do quoting part numbers. e.g. I want to control my type 'ABC123' energy IC made by Company123.inc with an Atmel ATmega88 or whatever.

I am not sure what 2-wire SPI is.
I know what a I2C protocol is.
I know what a PIC16F877A is. It can do I2C or 3-wire SPI or 4-wire SPI.

David.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
lineage2202
PostPosted: Feb 02, 2010 - 01:23 PM
Newbie


Joined: Feb 02, 2010
Posts: 3


i want to initiate a SPI communication between "PIC16F877A(master)" and "STPM01(slave)". the operation will be like this, the STPM01 will measure electrical energy consumption from the load and then store it in its embedded energy registers. when i want to get the energy data from STPM01, i must send serial clocks to it but instead of 3 wire SPI the STPM01 implements a 2 wire SPI, one for DATA pin and the other for serial CLOCK input..the master(PIC) will be the one initiating the clock..
 
 View user's profile Send private message  
Reply with quote Back to top
david.prentice
PostPosted: Feb 02, 2010 - 02:00 PM
10k+ Postman


Joined: Feb 12, 2005
Posts: 16544
Location: Wormshill, England

From a brief look at the STP01 data sheet, it does not really seem to behave like a regular I2C device.

So I would just stick with 4-wire SPI and be done with it.

The PIC18F877 has a MSSP module, and you configure it for SPI.

This is an Atmel site. All AVRs can do SPI. You will have a similar procedure to using the Microchip parts.

Google is your friend.

David.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
lineage2202
PostPosted: Feb 02, 2010 - 02:24 PM
Newbie


Joined: Feb 02, 2010
Posts: 3


as what i've understand, only two("SDAT" & "SCL")of the four pins of the STPM01's SPI module that will be connected to the SPI module of the PIC..the other two("SCS" & "SYN") will be connected to any general purpose I/O pin..because the "SCS" and "SYN" controls the function of the SDAT pin..the SDAT pin can be configured as input or outpin pin for data..so i think only the SDAT & SCL pin can be connected to the SPI module of the PIC(SDA & SCK)..because when the master sends serial clock to the slave, the data from the slave will be shifted to the master(PIC)..

i think a 2-wire SPI will be implemented in the PIC..
 
 View user's profile Send private message  
Reply with quote Back to top
david.prentice
PostPosted: Feb 02, 2010 - 03:45 PM
10k+ Postman


Joined: Feb 12, 2005
Posts: 16544
Location: Wormshill, England

Section 9.1 of the PIC16F8X data sheet.
Quote:
The SPI mode allows 8 bits of data to be synchronously
transmitted and received simultaneously. All four
modes of SPI are supported. To accomplish communication,
typically three pins are used:
• Serial Data Out (SDO)
• Serial Data In (SDI)
• Serial Clock (SCK)
Additionally, a fourth pin may be used when in a Slave
mode of operation:
• Slave Select (SS)


I am sure that you can use the different modes of the STPM01. You have to read the STPM01 data sheet. It is easier to use the "standard" interface.

You can use the PIC MSSP in different modes too.

David.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
juaquin
PostPosted: Apr 25, 2010 - 05:08 AM
Newbie


Joined: Apr 25, 2010
Posts: 4


donblake wrote:
Hey - attachments are now working!
donblake wrote:
FWIW, I just got slave TWI (I2C) working on a ATTiny2313 using USI. It's based on Atmel's AVR312 Application Note. I ported the code to WINAVR GCC, did some cleanup and fixed several errors. If anyone's interested, I can make it available.

Here it is. I've tested slave receive but not slave transmit. Use at your own risk. Enjoy.

Don


This is going to sound dumb, so I apologize in advance, but I haven't done much work with AVRs and I've run into a problem using this. Where do I put these files? I've dropped them into the winavr/avr/include/avr folder (where the other headers like io.h reside) and when I reference it, I end up in something of an infinite loop as it tries to include it over and over, it seems. Here's what I'm doing:
Code:
/*Includes*/
#include <avr/io.h>
#include <avr/iotn2313.h>
#include <util/delay.h>
#include <avr/usiTwiSlave.h>

and the result:

Code:

> "make.exe" all
avr-gcc -Wall -Os -DF_CPU=8000000 -mmcu=attiny2313 -c main.c -o main.o
In file included from c:/winavr-20100110/lib/gcc/../../avr/include/avr/usiTwiSlave.h:44,
                 from c:/winavr-20100110/lib/gcc/../../avr/include/avr/usiTwiSlave.h:44,
                 from c:/winavr-20100110/lib/gcc/../../avr/include/avr/usiTwiSlave.h:44,
                 from c:/winavr-20100110/lib/gcc/../../avr/include/avr/usiTwiSlave.h:44,
                 from c:/winavr-20100110/lib/gcc/../../avr/include/avr/usiTwiSlave.h:44,
                 from c:/winavr-20100110/lib/gcc/../../avr/include/avr/usiTwiSlave.h:44,

etc etc

If anyone has any links on where to put header/c files and how to include them, that would be great - a search didn't lead me to anything that seemed immediately relevant.
 
 View user's profile Send private message  
Reply with quote Back to top
david.prentice
PostPosted: Apr 25, 2010 - 08:52 AM
10k+ Postman


Joined: Feb 12, 2005
Posts: 16544
Location: Wormshill, England

I would delete all the directories in your WinAVR installation and re-install.

Personally, I never add "weird" include files to the system include directories.

Either add the 'weirdo' directory to your project, so it searches the system directories and your weirdo one.

Or you copy the weird.h to your project directory and access with #include "weird.h".

Remember that avr-cpp searches for <weird.h> and "weird.h" in different ways.

If you are going to use a respected library regularly, the first method is preferable.

Note that if the "weird.h" is from an unknown source, it is worth checking it over carefully. In particular for guards against multiple inclusion.

David.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
juaquin
PostPosted: Apr 25, 2010 - 09:16 AM
Newbie


Joined: Apr 25, 2010
Posts: 4


david.prentice wrote:
Or you copy the weird.h to your project directory and access with #include "weird.h".


Thanks, this is exactly what I was looking for. It's been awhile since my last programming class and this jogged my memory - now I'm embarrassed I forgot. Embarassed Perhaps it's time to open up an old textbook for a refresher.
 
 View user's profile Send private message  
Reply with quote Back to top
juaquin
PostPosted: Apr 27, 2010 - 02:05 AM
Newbie


Joined: Apr 25, 2010
Posts: 4


One last problem when I run make:
Code:
usiTwiSlave.h:257: error: `TWI_RX_BUFFER_SIZE' undeclared here

Same thing with TWI_TX_BUFFER_SIZE, TWI_TX_BUFFER_MASK, and TWI_RX_BUFFER_MASK. I'm assuming this is a simple matter of defining these with an appropriate value, but am not sure what those values should be.
 
 View user's profile Send private message  
Reply with quote Back to top
juaquin
PostPosted: Apr 27, 2010 - 02:38 AM
Newbie


Joined: Apr 25, 2010
Posts: 4


Nevermind, answered my own question with a little google-fu. For those with the same question, here's a little more documentation (especially on buffer sizes and masks): http://wtfmoogle.com/wiki/index.php/UsiTwiSlave.h

It seems that somehow my .h file was the same as the .c, so I was missing those definitions. Thanks for the great code!
 
 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