Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

After bootloader works, but through the programmer does not
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2335

blank.gif
PostPosted: Thu Mar 19, 2015 6:46 pm    Post subject: Reply with quote

sasha_1973 wrote:
In an occasion (to Const Const_realization_spi = 0 or = 1), doesn't matter, both options don't work!

And still I wait for your report, what happens if PB2 is set to output while hardware SPI is used...
Back to top
View user's profile
sasha_1973

Bascom Member



Joined: 30 Jul 2013
Posts: 58

ukraine.gif
PostPosted: Thu Mar 19, 2015 6:52 pm    Post subject: Reply with quote

Прошу прощения, но я ничего не могу понять!

I apologize, but I can understand nothing!
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2335

blank.gif
PostPosted: Thu Mar 19, 2015 7:06 pm    Post subject: Reply with quote

sasha_1973 wrote:
I apologize, but I can understand nothing!


I wait for you to write:
Code:
Config PortB.2 = Output

in your code, compile with hardware-SPI and then report the result here.
Back to top
View user's profile
sasha_1973

Bascom Member



Joined: 30 Jul 2013
Posts: 58

ukraine.gif
PostPosted: Thu Mar 19, 2015 7:18 pm    Post subject: Reply with quote

Const Const_realization_spi = 0 ' If "0" - implementation of hardware (hardware terminals), if "1" - implementation of software (any conclusions)

#if Const_realization_spi = 0
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = High , Phase = 0 , Clockrate = 4 , Noss = 1
#endif

#if Const_realization_spi = 1
Config Spi = Soft , Din = Pind.5 , Dout = Portd.6 , Clock = Portd.7 , Ss = None
#endif

Cs_max7219 Alias Portb.0 : Config Cs_max7219 = Output

Config PortB.2 = Output

Spsr.0 = 1 ' F_spi = F_osc / 2; Double Speed (CK/2) Master SPI Mode

Spiinit
Waitms 50




So???
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2335

blank.gif
PostPosted: Thu Mar 19, 2015 7:47 pm    Post subject: Reply with quote

sasha_1973 wrote:
So???

Yes.
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 1136

poland.gif
PostPosted: Fri Mar 20, 2015 9:50 am    Post subject: Reply with quote

Sasha please back to check basic.
During programming, the other systems do not interfere with the transmission because the Chip Select pin is high.
Try to pull up the pin to the positive or at the time of programming, remove the chips.

You can also try to verify the contents of the programming
Maybe something pulls the CS pin to ground and activates the external circuit connected on the SPI
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 6198
Location: Holland

blank.gif
PostPosted: Fri Mar 20, 2015 10:25 am    Post subject: Reply with quote

As MWS tries to explain (with lot of patience) : when using HW SPI and NOSS=1, you MUST configure the SPI dedicated SS pin which is PORTB.2 for this chip, to OUTPUT mode before SPIINIT is used. Even if this pin is not used for the SPI SLAVE hardware.
The reason why it works with the bootloader is that the boot loader had this code :
'we use some leds as indication in this sample , you might want to remove it
Config Pinb.2 = Output
Portb.2 = 1 'the stk200 has inverted logic for the leds

Note that it is important that you do so BEFORE the SPIINIT command. It does not seem to work after the SPI has been enabled.

_________________
Mark
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2335

blank.gif
PostPosted: Fri Mar 20, 2015 12:32 pm    Post subject: Reply with quote

albertsm wrote:
As MWS tries to explain (with lot of patience)

I've put the slow progress on translation problems, as the result of Google's or other services translation of Englisch/Russian back and forth is hard to understand.
Quote:
The reason why it works with the bootloader is that the boot loader had this code :
Config Pinb.2 = Output
Portb.2 = 1 'the stk200 has inverted logic for the leds

Wouldn't it be better to restore registers used by the bootloader, or use a watchdog reset, so user code can start on a clean machine?
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 6198
Location: Holland

blank.gif
PostPosted: Fri Mar 20, 2015 1:20 pm    Post subject: Reply with quote

yes, too bad things get missed in translation. But these translators do a great job.

the best way for a reset is timing out the watchdog so you get a proper reset.
resetting all used ports/registers could be an idea but it depends on the application. maybe a user wants to configure some things in the loader and keep it that way in the main program. for example ports that must be set.
And the user is in control.
Do not forget : the bootloader is just a simple example.

_________________
Mark
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2335

blank.gif
PostPosted: Fri Mar 20, 2015 2:09 pm    Post subject: Reply with quote

albertsm wrote:
resetting all used ports/registers could be an idea but it depends on the application.

In case of the TO his code would have never worked and so he never would have had the chance to experience that "mystery" Very Happy
Quote:
But these translators do a great job.

Well, after I have seen the results Russian/English, English/Russian, I can not share your opinion.
Back to top
View user's profile
sasha_1973

Bascom Member



Joined: 30 Jul 2013
Posts: 58

ukraine.gif
PostPosted: Fri Mar 20, 2015 2:13 pm    Post subject: Reply with quote

EDC wrote:
Sasha please back to check basic.
During programming, the other systems do not interfere with the transmission because the Chip Select pin is high.
Try to pull up the pin to the positive or at the time of programming, remove the chips.

You can also try to verify the contents of the programming
Maybe something pulls the CS pin to ground and activates the external circuit connected on the SPI




Все проверено и перепроверено 1000 раз. Остальные исходники, где есть работа с SPI работают!

Everything is checked and rechecked 1000 times. Other source codes where there is a work work with SPI!
Back to top
View user's profile
sasha_1973

Bascom Member



Joined: 30 Jul 2013
Posts: 58

ukraine.gif
PostPosted: Fri Mar 20, 2015 2:31 pm    Post subject: Reply with quote

Огромное СПАСИБО всем за помощь!
Может объясните простыми словами, что надо сделать для работы исходника?

Many thanks to all for the help!
Maybe explain with simple words what it is necessary to make?
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 6198
Location: Holland

blank.gif
PostPosted: Fri Mar 20, 2015 2:58 pm    Post subject: Reply with quote

Quote:
Well, after I have seen the results Russian/English, English/Russian, I can not share your opinion.

no i imagine that, but i was thinking about the time i had to use other software and the translation was even worse.

Quote:
Maybe explain with simple words what it is necessary to make for work of a source code?


instead of :
Code:
  Cs_max7219 Alias Portb.0 : Config Cs_max7219 = Output

  Spsr.0 = 1 : Spcr.0 = 0 : Spcr.1 = 0       ' F_spi = F_osc / 2; Double Speed (CK/2) Master SPI Mode

  Spiinit
  Waitms 50


use :


Code:
  Cs_max7219 Alias Portb.0 : Config Cs_max7219 = Output
CONFIG PORTB.2=OUTPUT
PORTB.2=1  ' i did not check to what it is connected
  Spsr.0 = 1 : Spcr.0 = 0 : Spcr.1 = 0       ' F_spi = F_osc / 2; Double Speed (CK/2) Master SPI Mode

  Spiinit
  Waitms 50



if that that does not work, make sure you VERIFY after your program. AND that the reset vector is set to the application (0).

_________________
Mark
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2335

blank.gif
PostPosted: Fri Mar 20, 2015 3:20 pm    Post subject: Reply with quote

As long the SS is output:
Code:
CONFIG PORTB.2=OUTPUT

the pin-value is "don't care", so that's not necessary:
albertsm wrote:
Code:
PORTB.2=1

In this case it would come forward to use the SS-pin as CS.
Data-sheet ATM328P:
Quote:
If SS is configured as an output, the pin is a general output pin which does not affect the SPI system. Typically, the pin will be driving the SS pin of the SPI Slave.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 6198
Location: Holland

blank.gif
PostPosted: Fri Mar 20, 2015 3:35 pm    Post subject: Reply with quote

Quote:
the pin-value is "don't care", so that's not necessary:

yes i know the data sheet. No need to explain that to me! I did not checked the design or rest of the code, so maybe this pin is connected to some other slave, and since NOSS=0 worked, this will create the same code.

_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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