Author Topic: [AVR] programming two AVR's that are connected together on the SPI bus  (Read 6186 times)

0 Members and 1 Guest are viewing this topic.

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17816
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
I am making myself a development board to play with the spi bus and later CAN. To start with I want to experiment with SPI between 2 AVR's, but that means connecting their SPI pins together, the same pins that are used to program the devices.

I think this will work providing I only hold in reset the one that I am programming. Is this correct ?
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9951
  • Country: nz
Re: [AVR] programming two AVR's that are connected together on the SPI bus
« Reply #1 on: December 19, 2015, 08:39:48 am »
If you use 3x ~1k resistors to link clk/miso/mosi between mcus it will be fine. The programmer can connect direct and pull the pins either way. Even if the other mcu is active and trying to push data.

If you want to get fancy you can always use a tristate buffer in between them.
« Last Edit: December 19, 2015, 08:44:20 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17816
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [AVR] programming two AVR's that are connected together on the SPI bus
« Reply #2 on: December 19, 2015, 08:43:55 am »
so long as I only reset the chip I am programming presumably or I'll be trying to program both at once.
 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
Re: [AVR] programming two AVR's that are connected together on the SPI bus
« Reply #3 on: December 19, 2015, 08:51:17 am »
Actually an interesting question -- you think, those 1k resistors wouldn't be necessary if I could disable the drivers on the non-being-programmed MCU. How do you disable the drivers? One way is to hold the chip in reset -- oh wait..

It's also annoying that the SPI pins switch direction based on master vs slave. If they had SDO and SDI pins, there again wouldn't be a need for 1k resistors.

Gah, there must be a better way!

so long as I only reset the chip I am programming presumably or I'll be trying to program both at once.

Yes, that's implied
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9951
  • Country: nz
Re: [AVR] programming two AVR's that are connected together on the SPI bus
« Reply #4 on: December 19, 2015, 08:51:54 am »
If you have the resistors in series you cant have one programming interface for both chips, since the programmer will need to go through the resistors in one of the directions.

Is your idea to short  MOSI MISO CLK to each mcu and also to the programmer then put a two way switch on the reset pin?
The issue with this is that the mcu not in reset may try to output data during programming.
You could have two "enabled" line between them (active low) and enable pullups.
This way if a mcu is in reset the other mcu can detect it and set its spi pins tristate.

Edit, thinking about it some more, i think you will have problems with that.
Since MOSI / MISO will be around the wrong way for one of the mcus to be programmed.
« Last Edit: December 19, 2015, 08:59:09 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17816
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [AVR] programming two AVR's that are connected together on the SPI bus
« Reply #5 on: December 19, 2015, 08:56:18 am »
Actually don't think the whole idea will work, if I connect the two AVR's together I will have a problem when I also connect the CAN interfaces that will enable the 2 AVR's to talk to each other on CAN as then both AVR's need to be masters to drive their own slave CAN controllers and there will be collisions on the SPI bus. I need to take this one step at a time. Maybe have a programming header per chip and put the 1K resistors in the bus lines so that the programmer can over ride the data from the other chip, not that there should be any.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17816
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [AVR] programming two AVR's that are connected together on the SPI bus
« Reply #6 on: December 19, 2015, 09:02:00 am »


Edit, thinking about it some more, i think you will have problems with that.
Since MOSI / MISO will be around the wrong way for one of the mcus to be programmed.

why ? I thought on SPI all the MOSI are connected together and all the MISO are connected together, as the system can be multi master, although my problem will come later when I want 2 masters at once, I think I'll just put a jumper between themso that I can break the SPI link and then each AVR can become a master with it's own bus to drive the CAN interfaces.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9951
  • Country: nz
Re: [AVR] programming two AVR's that are connected together on the SPI bus
« Reply #7 on: December 19, 2015, 09:05:45 am »
I have a solution

Use one of the AVRs that doesnt have the programming interface on the SPI lines.
Some have it on other pins, i forget which

Solves all the issues.


why ? I thought on SPI all the MOSI are connected together and all the MISO are connected together, as the system can be multi master

True, yeah if your system will be multi master it wont matter.
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline AndreasF

  • Frequent Contributor
  • **
  • Posts: 251
  • Country: gb
    • mind-dump.net
Re: [AVR] programming two AVR's that are connected together on the SPI bus
« Reply #8 on: December 19, 2015, 09:13:08 am »
I would use "jumpers" to bridge the three SPI lines. During programming you can take them off and only connect to the side you're programming.

Multi-master SPI? I'm sure it's possible but seems complicated to do regarding arbitration. 
my random ramblings mind-dump.net
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9951
  • Country: nz
Re: [AVR] programming two AVR's that are connected together on the SPI bus
« Reply #9 on: December 19, 2015, 09:17:00 am »
You could just slap a 3rd mcu in there as a SPI hub (GPIO passthrough)


Have it as the hub for all SPI nodes, A B and the programmer. Give it control of the reset lines for A and B, then just have switches on it for what you want to do/program.
You could include reprogramming MCU-C itself as well, just use its own mosi/miso pins to connect to the programmer. It can use them as GPIO when doing passthrough and reprogramming A or B.
If you connect up its reset line to the programmer you will reprogram the hub.

Gives you flexibility if you want to add more SPI stuff later.
Only disadvantage (other than extra mcu) is you probably wont be able to run the MCUA - MCUB SPI coms at max clock rate, since the pass through will add some delay if its done in software.
« Last Edit: December 19, 2015, 09:29:38 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline miceuz

  • Frequent Contributor
  • **
  • Posts: 387
  • Country: lt
    • chirp - a soil moisture meter / plant watering alarm
Re: [AVR] programming two AVR's that are connected together on the SPI bus
« Reply #10 on: December 19, 2015, 09:44:02 am »
I have used 4053 in this exact case to control the direction of the clock signal.

I have two AVRs - slave and master communicating on SPI bus. During normal operation SCK lines of both are connected via 3k6 resistor, but when in reset, another line controlls which SCK line gets connected to programming SCK and which one grounded.


« Last Edit: December 19, 2015, 10:21:09 am by miceuz »
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17816
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [AVR] programming two AVR's that are connected together on the SPI bus
« Reply #11 on: December 19, 2015, 12:15:22 pm »
I would use "jumpers" to bridge the three SPI lines. During programming you can take them off and only connect to the side you're programming.

Multi-master SPI? I'm sure it's possible but seems complicated to do regarding arbitration.

I will do this, because then I can split the bus in two for when I want each AVR to be the master controlling it's own CAN chip (MCP2515) as well. This is just for experimenting so no need to go to much length. I need to learn to use both SPI ans CAN so am trying to put both on one vero board that I can carry around with me (yes relatives, here I come at christmas with something to do when I'm suppose to be visiting you, just need my board, laptop and programmer  8)).

What sort of frequency does SPI cope with over shoddy vero board wiring, if I had time I'd order PCB's
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17816
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [AVR] programming two AVR's that are connected together on the SPI bus
« Reply #12 on: December 19, 2015, 07:40:10 pm »
My efforts so far attached. Idea is to just have something to use as a test bed for SPI and CAN coms with regular reporgramming so that I can just have a few control options on buttons and feedback from an LED.
« Last Edit: December 19, 2015, 07:42:39 pm by Simon »
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 21688
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: [AVR] programming two AVR's that are connected together on the SPI bus
« Reply #13 on: December 19, 2015, 09:44:01 pm »
I'd suggest one common pin which is used as open collector.  One or both MCUs assert passive pull-up ('H') (or an external resistor is used), and each one checks pin state before asserting hard low ('0').  If it's already low, the other one must be talking, so hold on.

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17816
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [AVR] programming two AVR's that are connected together on the SPI bus
« Reply #14 on: December 19, 2015, 09:47:00 pm »
I may have run out of pins  :-[ It's just for some initial test. once i know what I'm doiung I'll probably get a few PCB's spun.
 

Offline commie

  • Frequent Contributor
  • **
  • Posts: 278
  • Country: gb
Re: [AVR] programming two AVR's that are connected together on the SPI bus
« Reply #15 on: December 19, 2015, 09:59:04 pm »
I'll probably get a few PCB's spun.

Hi Simon,

Quick question, given you reside in the U,K. like me, who manufactures your pcb's for you? The reason I ask is I'm looking for a viable company to make a few pcb's for me. Also, is there any chance you could give me a very average price for 160x100mm board ss and ds. Thanks ever so much.

Cheers
Commie
 

Offline dgtl

  • Regular Contributor
  • *
  • Posts: 183
  • Country: ee
Re: [AVR] programming two AVR's that are connected together on the SPI bus
« Reply #16 on: December 19, 2015, 10:09:16 pm »
Been there, done that, in 2007. My solution had a single programming connector with an extra pin.
1) The board had a jumper, that was used to select the reset line going to first or second AVR. Rest of the lines (MISO, MOSI, SCK) were connected to both.
2) The extra pin went to each AVR. The FW of both AVRs checked these pins on boot and if they were pulled low, the mcu FWs stayed in infinite loop and did not initialize the SPI pins as outputs. On the programming plug, this pin was shorted to GND. So when the programmer was plugged in, neither of the uc's started to boot. This way, nothing messed with the programming operation.
 

Offline obiwanjacobi

  • Frequent Contributor
  • **
  • Posts: 988
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: [AVR] programming two AVR's that are connected together on the SPI bus
« Reply #17 on: December 20, 2015, 08:07:28 am »
I am making myself a development board to play with the spi bus and later CAN. To start with I want to experiment with SPI between 2 AVR's, but that means connecting their SPI pins together, the same pins that are used to program the devices.

Does it have to be SPI? A synchronous USART connection should work too...

Otherwise have each AVR with its own ISP 6pin connector and connect them via a flatcable, you have to take off to do the programming...?

[2c]
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17816
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [AVR] programming two AVR's that are connected together on the SPI bus
« Reply #18 on: December 20, 2015, 08:21:20 am »
I am making myself a development board to play with the spi bus and later CAN. To start with I want to experiment with SPI between 2 AVR's, but that means connecting their SPI pins together, the same pins that are used to program the devices.

Does it have to be SPI? A synchronous USART connection should work too...

Otherwise have each AVR with its own ISP 6pin connector and connect them via a flatcable, you have to take off to do the programming...?

[2c]

Yes because the goal is to learn to control the MCP2515 via SPI having mastered the SPI bus, so I need to first learn and verify SPI function between two AVR's and then break the bus in two and start trying to control the CAN interfaces that will then connect the two AVR's
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17816
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [AVR] programming two AVR's that are connected together on the SPI bus
« Reply #19 on: December 20, 2015, 08:23:59 am »
I'll probably get a few PCB's spun.

Hi Simon,

Quick question, given you reside in the U,K. like me, who manufactures your pcb's for you? The reason I ask is I'm looking for a viable company to make a few pcb's for me. Also, is there any chance you could give me a very average price for 160x100mm board ss and ds. Thanks ever so much.

Cheers
Commie

PCB cart, I've also used techbridge circuits who are pricier but excellent and very very helpful.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf