View previous topic :: View next topic |
Author |
Message |
almatea
Joined: 22 Oct 2005 Posts: 64
|
Posted: Thu May 15, 2008 2:41 pm Post subject: SPI and SHIFTIN |
|
|
Dear All,
I`m using hard SPI for SD card. So, there are used options like Config Spi... Everything work great.
Now, I would like to add MAX6675 which work on SPI interface. I have found some solutions on forum for this converter. But there is no any options like Config SPI...
here is sample from mcs forum.
Code: |
Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portd.3 , Rs = Portd.2
dim A As Word
dim Loc_data As single
Config Lcd = 16 * 2 'configure lcd screen
Deflcdchar 0 , 12 , 2 , 4 , 8 , 14 , 32 , 32 , 32 '^2
'configure the MISO, SCK and /SS pins
Ddrb.2 = 1 'for cs
Ddrb.5 = 1 'for sck
Ddrb.4 = 0 'for so
Portb.2 = 1 'hi cs
Portb.5 = 0 'lo sck
Portb.4 = 1 'hi so
Max_cs Alias Portb.2
Max_sck Alias Portb.5
Max_so Alias Pinb.4
Cls
Lcd "MAX6675 " ; "AW" ; Chr(0) 'fun
Waitms 1000
'main_prog:
Do
Cls
Max_cs = 0 'cs lo
Shiftin Max_so , Max_sck , Loc_data , 0 , 16 'get data from max6675
Shift Loc_data , Right , 3 'get rid of d2-d0
Loc_data = Loc_data / 0.25
Max_cs = 1 'hi cs again
Lcd "Temp:= " : lcd Loc_data 'get the temperature
Wait 500 'wait for 1 second for the next read
Loop
end
|
If I will use SHIFTIN option to read some datas from this converter, I have to connect MAX6675 directly to the same pins used for SD Card?
Shortly - can I use SDA Card on SPI Hardware pins and read MAX6675 on another pins using SHIFTIN??
Regards |
|
Back to top |
|
|
ltdor
Joined: 14 Sep 2006 Posts: 11 Location: Romania
|
Posted: Thu May 15, 2008 5:26 pm Post subject: |
|
|
Quote: | Shortly - can I use SDA Card on SPI Hardware pins and read MAX6675 on another pins using SHIFTIN?? |
Sure you can do that.
But why not use the SPI hardware for both of them ? Share the MISO, MOSI, and SCK pins and use different CS pins (not /SS for any, it must stay configured as input tied to VCC or with pullups enabled). The unselected devices on SPI will stay in high impedance state and will not scramble the communication between controller and the selected device. |
|
Back to top |
|
|
almatea
Joined: 22 Oct 2005 Posts: 64
|
Posted: Thu May 15, 2008 5:58 pm Post subject: |
|
|
Than you Itdor for your answer.
Is that mean, that If I`m using SHIFTIN than I`m just using normal SPI?
Please, look at the code above.
Why there is no any CONFIG SPI direction?
Best Regards |
|
Back to top |
|
|
ltdor
Joined: 14 Sep 2006 Posts: 11 Location: Romania
|
Posted: Thu May 15, 2008 6:45 pm Post subject: |
|
|
If i understand clearly, you ask if SHIFTIN statement has anything to do with the normal SPI. Assuming you're talking about the hardware SPI module, then the answer is NO as long you don't share the same physical pins (which may disrupt both communications).
SHIFTIN is a software function that emulates only a subset of the hardware SPI module functionality (the reading part and not well at all) and can be used with almost any pin. It's not a complete/standard SPI type communication so it has no CONFIG SPI statement associated with it. You may use it anytime in your program and with almost any pins. These were the good news. The bad news is that you cannot control it as you control the hardware SPI (no phase, no clockrate)
So the answer to your initial question is YES. You can use both the SPI hardware module with the statements associated with it (CONFIG SPI, SPIOUT, SPIIN) to interface the SD card and SHIFTIN statement to interface MAX6675.
Or even more, you may use even more devices interfaced using SHIFTIN if you have enough free pins.
All you have to care is to not overlap the hardware SPI pins with the pins used by the SHIFTIN "software SPI". |
|
Back to top |
|
|
mattcro
Joined: 03 Oct 2007 Posts: 327 Location: Scotland
|
Posted: Tue Jun 03, 2008 11:05 am Post subject: |
|
|
You can have several SPI devices connected to the hardware SPI interface, provided they use the same SPI mode (phase/polarity). I'm working on a project that uses an SD card, a SPI RTC and a SPI UART on the M2561's hardware SPI bus with no conflicts. Each device has its own CS pin and the MOSI/MISO/SCLK pins are shared.
You can use the SS pin as a general purpose output (or CS output for one of the SPI devices) provided you use the NOSS=1 option in CONFIG SPI. You can't use the SS pin as an input since pulling it low will change the hardware SPI to slave mode.
SHIFTIN and SHIFTOUT are independent of hardware/software SPI. They are just very simple software-timed single-byte serial in/out commands. The SPIIN/SPIOUT/SPIMOVE commands do proper hardware/software SPI transfers. _________________ If all else fails, read the manual. Even better: read the manual before something fails. If you can't find it in the manual, search the forum.
BascomAVR 2.0.8.5 |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|