View previous topic :: View next topic |
Author |
Message |
Mrshilov
Joined: 24 Jan 2009 Posts: 314 Location: Russia
|
Posted: Mon Mar 07, 2016 2:24 pm Post subject: Two SPI devices |
|
|
I use SD-card with AVR-DOS and touch panel (XPT2046) on the same SPI-port D of Atxmega128A4. Both works fine. But when I use touch :
Code: | Open "SPID" For Binary As #14
...... read data from XPT2046
Close #14 |
after that file reading from SD-card is wrong, but repeat reading is good. To solve this problem after using touch I make dummy open/close SD, open again and read:
Code: | Open Filename For Binary As #12
Close #12
Open Filename For Binary As #12
...... read data from SD
Close #12 |
I think it's not a best solution. How to do it right? |
|
Back to top |
|
|
mmarlette
Joined: 30 Nov 2007 Posts: 311 Location: Delano, MN
|
Posted: Mon Mar 07, 2016 5:27 pm Post subject: |
|
|
Try using the CS line for the devices
AVR-DOS is probably always active.
Can try something like this
Code: |
Sub Server_SDActivate()
'
'*******************************************************************************
' Activate SPI SD Card
'*******************************************************************************
'
Set W5x00_CS~ ' disable WIZnet chip
Reset SDLED~ ' turn on, SD active LED
Reset Mmc_cs ' enable SD Card
#if Debugflag
Print #Debugchannel, "Server_SDActivate, SD Card is active"
#endif
End Sub
Sub Server_W5x00Activate()
'
'*******************************************************************************
' Activate SPI Wiz812 W5x00
'*******************************************************************************
'
Set Mmc_cs ' disable SD Card
Set SDLED~ ' turn off, SD active LED
Reset W5x00_CS~ ' enable WIZnet chip
#if Debugflag
Print #Debugchannel, "Server_W5x00Activate, W5x00 is active"
#endif
End Sub
|
In the above example you can see the device you want to talk to is being enabled and the other SPI devices are being disabled via the CS lines.
Hopefully this is what you meant.
Regards,
Mark |
|
Back to top |
|
|
Mrshilov
Joined: 24 Jan 2009 Posts: 314 Location: Russia
|
Posted: Mon Mar 07, 2016 7:15 pm Post subject: |
|
|
Of course I already use separate CS lines. Without it devices will conflict. |
|
Back to top |
|
|
mmarlette
Joined: 30 Nov 2007 Posts: 311 Location: Delano, MN
|
Posted: Mon Mar 07, 2016 7:25 pm Post subject: |
|
|
I guess I missed that statement in your originally message.
Then I would look at when you enable/disable the devices. |
|
Back to top |
|
|
Mrshilov
Joined: 24 Jan 2009 Posts: 314 Location: Russia
|
Posted: Tue Mar 15, 2016 5:16 pm Post subject: |
|
|
Second trouble with two devices - program hangs then goes to subroutine after using second SPI device. |
|
Back to top |
|
|
Mrshilov
Joined: 24 Jan 2009 Posts: 314 Location: Russia
|
Posted: Sun Apr 03, 2016 1:30 am Post subject: |
|
|
After many experiments I found what while CS on SD-card is 1 (card disabled), activity on SPI bus make some changes inside card. Maybe counters or registers. In result errors with loading data via AVR-DOS and even file corrupt.
In my case (SD-card + Touch) I try compromise: MOSI & MISO are common for both devices, but SCK lines are separate. SD-card works with hardware SPI, touchscreen works with Shiftin/Shiftout while SPI is disable (Spid_ctrl = 144). It works fine. |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Sun Apr 03, 2016 9:12 am Post subject: |
|
|
This is very strange as it is working with Arduino W5100 shield
SD memory card and W5100 on SPI bus
Regards Paul |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Fri Apr 08, 2016 3:19 pm Post subject: |
|
|
Quote: | After many experiments I found what while CS on SD-card is 1 (card disabled), activity on SPI bus make some changes inside card. Maybe counters or registers. In result errors with loading data via AVR-DOS and even file corrupt.
In my case (SD-card + Touch) I try compromise: MOSI & MISO are common for both devices, but SCK lines are separate. SD-card works with hardware SPI, touchscreen works with Shiftin/Shiftout while SPI is disable (Spid_ctrl = 144). It works fine. |
yes that makes sense. the cards have a bit of an odd handling : clock pulses must be sent when the CS is disabled !!!
So when you apply pulses to other devices, the card will see these pulses and get confused. i do not know why any SPI device is allowed to work outside the SPI specification but that is something else.
In any case, you can use a bus driver which will isolate the lines, or you can do as you found, use a different clock line. _________________ Mark |
|
Back to top |
|
|
|