how would I connect my SPI pins (master) to slave device...

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

Hi,

I am trying to use SPI interface to have my ATMEGA8 acting a master to the TC77 temperature sensor, which supports SPI but only has 3 pins. They are: SCK, /CS, and SI/O. It does not have the MOSI/MISO pins separately.

How would I connect my ATMEGA8 to the TC77 to support SPI communication? Both ATMEGA8's MOSI and MISO pins connected to the TC77's SI/O pin?

Thanks

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

There is a scheme that uses a small FET to separate the two signals at the master. There have been a few threads, here, on how to do it.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

ka7ehk wrote:
There is a scheme that uses a small FET to separate the two signals at the master. There have been a few threads, here, on how to do it.

Jim

Schematic in the datasheet? Could you point out the threads? Thanks

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

[deleted, OP doesn't care]

Stealing Proteus doesn't make you an engineer.

Last Edited: Fri. Jan 14, 2011 - 06:25 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I can't yet find what I remember but this ought to work.

Use an NChan FET on the MOSI pin of the master, gate to MOSI, drain to the data bus, source to ground. Add pull-up resistor to data bus because you now have an "open drain" driver. Load the transmit register with the complement of the data you want to send (because the FET inverts). When the transmit is done, load the transmit register with 0x00 and keep on clocking to get the returned data. Sending 0x00 makes the FET "open", allowing the device at the other end to put its data on the line.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

ArnoldB wrote:
[deleted, OP doesn't care]

Uhmmm...Why delete it? I was about to try your suggestion!

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

Why not just connect MOSI and MISO together and put the AVR MOSI pin as input when expecting data from TC77? OK so it won't work if you have other devices on bus. For slow communications, how about just connecting MOSI and MISO together with say 4k7 resistor?

When it is so complicated, why use hardware SPI at all, just use any pins and wiggle them however you like in software.

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

Jepael wrote:

When it is so complicated, why use hardware SPI at all, just use any pins and wiggle them however you like in software.

That's what I am seeing in other examples, that is, just use it like TWI, but I am looking to control more than one SPI device. I guess it's ok even with that. I just de-initialize SPI stuff when interface with this temperature sensor.

There is one tiny problem of NOT using SPI to control this temperature sensor, and that is that I have to provide a 4Mhz clock input to the sensor, but I am running at 16Mhz. The SPI interface let me do that with a clock divided by 4 option. How would I make sure to do 4Mhz for this temperature sensor while running at 16Mhz?
Some sort of pre-scaler, but how would I implement that.

Thanks.

Last Edited: Fri. Jan 14, 2011 - 08:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Arnold gave you the exact procedure for reading / writing to your TC77.

Since it is unlikely that you ever want to NOT read the temperature, you could forget about MOSI altogether. Just put a 47k pull-down resistor on your SO/SI pin.

The data sheet explains exactly how to use the device.
You simply set the SPI clock divider to F_CPU/4 to get 4MHz @ 16MHz F_CPU.

Since you are not very good at reading people's advice, why not quote the paragraph number and Figure # of anything you do not understand. This is what data sheets are for !!

David.

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

david.prentice wrote:
Arnold gave you the exact procedure for reading / writing to your TC77.

and arnold got offended somehow and erased his post, which I posted "Uhmmm...Why delete it? I was about to try your suggestion!"

Quote:

The data sheet explains exactly how to use the device.
You simply set the SPI clock divider to F_CPU/4 to get 4MHz @ 16MHz F_CPU.

I knew that, as usual you NEVER read people's responses and think that whatever you say is God's word for people to follow. See "The SPI interface let me do that with a clock divided by 4 option." in one of my responses.

Quote:

Since you are not very good at reading people's advice

Let me quote what YOU once said: "Don't believe what is written on the internet." More or less verbatim.

I think you and Arnold have an insecurity problem. If people don't respond to your posts/answers, it does not mean they didn't read or throw them away. Don't assume that whatever you say is a golden word.

Thank you, David, but do me favor. Please don't answer my posts, because every single time you seem to have condescending responses.

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

unebonnevie wrote:

There is one tiny problem of NOT using SPI to control this temperature sensor, and that is that I have to provide a 4Mhz clock input to the sensor, but I am running at 16Mhz. The SPI interface let me do that with a clock divided by 4 option. How would I make sure to do 4Mhz for this temperature sensor while running at 16Mhz?
Some sort of pre-scaler, but how would I implement that.

Thanks.

Who says you have to use 4MHz SCK to talk to the sensor? It is perfectly happy with any clock frequency between 0Hz and 7MHz. Although it would take forever to read results at 0Hz :)

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

Jepael wrote:
unebonnevie wrote:

There is one tiny problem of NOT using SPI to control this temperature sensor, and that is that I have to provide a 4Mhz clock input to the sensor, but I am running at 16Mhz. The SPI interface let me do that with a clock divided by 4 option. How would I make sure to do 4Mhz for this temperature sensor while running at 16Mhz?
Some sort of pre-scaler, but how would I implement that.

Thanks.

Who says you have to use 4MHz SCK to talk to the sensor? It is perfectly happy with any clock frequency between 0Hz and 7MHz. Although it would take forever to read results at 0Hz :)

The spec does say a max. of 7Mhz for the clock freq to use clocking the TC77. 4Mhz is nice because I am using 16Mhz crystal for my ATMEGA8, and SPI lets me divide the clock by 4, thus, 4Mhz for the SPI to control the TC77.

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

First you had to do exactly 4MHz, now you want to do it with hardware SPI because it can provide you exactly 4MHz.

I am just wondering why, as bit-banging the bus would let you easier, direct connection to AVR albeit with arbitrary but reasonably fast clock, and still you want exactly 4MHz and more complex hardware to connect it to hardware SPI.

Well, I don't have to understand :)

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

Jepael wrote:
First you had to do exactly 4MHz, now you want to do it with hardware SPI because it can provide you exactly 4MHz.

I am just wondering why, as bit-banging the bus would let you easier, direct connection to AVR albeit with arbitrary but reasonably fast clock, and still you want exactly 4MHz and more complex hardware to connect it to hardware SPI.

Well, I don't have to understand :)

Pardon...That's because you didn't read my responses carefully. I want to use SPI rather than bit banging, because I am looking to control more than one SPI slave. It is true that the TC77 can be easily be controlled with bit-banging, also known as TWI, two-wire interface, more precisely MICROWIRE interface with the TC77, which I mentioned earlier as a response to your question.

I would like to have 4Mhz exactly, because I have to use the 16Mhz crystal for my ATMEGA8, and the 4Mhz happens to be the one divisible by 4 with SPI's PRI0 and PRI1 bits set as zeros. That is, I don't want to use 2Mhz, 16Mhz/8, which is the only option left. And obviously I can't use the full blown 16Mhz on the TC77, because it is rated at 7Mhz max.

I also mentioned earlier [the response to your 1st post to me] that for me to use the TWI approach, that is, bit-banging, I would need to know how to slow down to 4Mhz from the 16Mhz crystal speed. I do realize that the TC77 can take up to 7Mhz, but, working with powers of two is much easier.

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

Quote:
It is true that the TC77 can be easily be controlled with bit-banging, also known as TWI, two-wire interface, more precisely MICROWIRE interface with the TC77, which I mentioned earlier as a response to your question.

I accept that you do not want me or Arnold to reply, but your above statement is completely untrue. TWI is nothing to do with MicroWire.

It is entirely possible to use the Atmel SPI peripheral, and to have other SPI devices on the bus.

Likewise it is entirely possible to bit-bang and still use the SPI for other devices.

All the replies that you have had have been (IMHO) accurate and practical. Some better than others. You do not want to know anything from Arnold or myself.

Read up on MicroWire on Wikipedia. Read about Atmel TWI on any AVR data sheet.

David.

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

I totally agree with David.

TC77 can exist on a separate bus if you like.

And by definition, bit-bang is slow to begin with. And to make it slower you use delays.