Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Soft-SPI working - HW-SPI not working

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
boeseturbo

Bascom Member



Joined: 23 Jul 2007
Posts: 65

blank.gif
PostPosted: Wed Jul 08, 2015 9:04 am    Post subject: Soft-SPI working - HW-SPI not working Reply with quote

Hi friends,

I playing with a OLED display and use hkipniks SSD1306 code. I trying to convert Software-SPI to Hardware. I replaced shiftout with spiout command...

Config Spi = Soft , Din = Pinb.0 , Dout = Portb.2 , Ss = none , Clock = Portb.1
spiinit

REM Shiftout Data_out , Lcd_clk , Ddata(point) , 1 , 8 ', 2
spiout ddata(point),1

this code is working fine


When I try to use hardware SPI with my Arduino MEGA2560 with this code:


Config Spi = Hard, Interrupt = off, Data Order = msb, master = yes, Polarity = High, Phase = 1, Clockrate = 16, Noss = 1
spiinit
spiout ddata(point),1

it is not working.

SPI is connected right (Portb.2 MOSI to SDIN D1 - Portb.1 SCLK D0).

All other connections (ChipSelect, Reset, R/W) I leave like in the Software-SPI Test...

Has anybody an idea where my fault is?

Cheers

Paul

(BASCOM-AVR version : 2.0.7.8 )
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2335

blank.gif
PostPosted: Wed Jul 08, 2015 9:28 am    Post subject: Re: Soft-SPI working - HW-SPI not working Reply with quote

boeseturbo wrote:
Config Spi = Hard, Interrupt = off, Data Order = msb, master = yes, Polarity = High, Phase = 1, Clockrate = 16, Noss = 1
Has anybody an idea where my fault is?

You do not set the SS-pin to output, or pull it high while being input. Noss = 1 only says, that Bascom's spiout command does not take control over the SS-pin, nonetheless in master mode the SS-pin has to be configured as mentioned.
This is also stated in the help under Config SPI, it even is highlighted with an exclamation mark in yellow triangle, not to be missed by the user.
Back to top
View user's profile
boeseturbo

Bascom Member



Joined: 23 Jul 2007
Posts: 65

blank.gif
PostPosted: Wed Jul 08, 2015 9:44 am    Post subject: Reply with quote

Hi,

I set the chipselect pin manually So I dont need SS pin of hardware SPI...

Cheers
Back to top
View user's profile
boeseturbo

Bascom Member



Joined: 23 Jul 2007
Posts: 65

blank.gif
PostPosted: Wed Jul 08, 2015 9:52 am    Post subject: Reply with quote

I set now SS pin over hardware SPI, not manually set it. Now it is working...

Cheers and thank you very much for your tip!

Cheers
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2335

blank.gif
PostPosted: Wed Jul 08, 2015 10:11 am    Post subject: Reply with quote

boeseturbo wrote:
I set now SS pin over hardware SPI, not manually set it. Now it is working...

Quote:
I set the chipselect pin manually So I dont need SS pin of hardware SPI...

It doesn't matter how you control CE of the hardware, you can hard wire it and have it disconnected from SS.
Critical however is, that you set the SS-pin to its required state for running SPI in master mode, this is simply a requirement by the SPI hardware within the AVR.
Back to top
View user's profile
boeseturbo

Bascom Member



Joined: 23 Jul 2007
Posts: 65

blank.gif
PostPosted: Fri Jul 10, 2015 8:00 am    Post subject: Reply with quote

thank you very much for this information Smile

Cheers
Back to top
View user's profile
Darthinvader

Bascom Member



Joined: 09 Jul 2015
Posts: 4

PostPosted: Sat Jul 11, 2015 11:35 am    Post subject: Reply with quote

Hi, i'm using this
Config >
Ddrb = &B10111110 : Spcr = &B01010000

Spdr = datatosend
Bitwait Spsr.7 , Set

I dont care about driving SS, just CE = 1 if i' sending data and thats it.
Working like a charm.
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2335

blank.gif
PostPosted: Sat Jul 11, 2015 5:30 pm    Post subject: Reply with quote

Darthinvader wrote:

Ddrb = &B10111110 : Spcr = &B01010000
I dont care about driving SS, just CE = 1 if i' sending data and thats it.
Working like a charm.

If you refer with your post to an ATMega2560, I'd say: don't distribute your nonsense, otherwise finally someone believes it and wonders why it won't work.
Your config shows SS (PINB0) to be set as input. In this configuration, SS has to be pulled high for master mode.
Whether this is done by static charge or a high value resistor, doesn't matter, as long the level on SS is high, it will work, only it would not be reliable.
If you don't understand the mechanisms of SPI, I'd advise to RTFM before posting.
Back to top
View user's profile
Pzx

Bascom Member



Joined: 05 May 2015
Posts: 39

poland.gif
PostPosted: Fri Feb 17, 2017 1:13 pm    Post subject: Reply with quote

Hello,

can anyone post a link or copy whole Bascom code that is mentioned at the begining of this post? I can not find it.

Thanks in advance
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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