View previous topic :: View next topic |
Author |
Message |
MWS
Joined: 22 Aug 2009 Posts: 2259
|
Posted: Thu Mar 19, 2015 6:46 pm Post subject: |
|
|
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 |
|
|
sasha_1973
Joined: 30 Jul 2013 Posts: 58
|
Posted: Thu Mar 19, 2015 6:52 pm Post subject: |
|
|
Прошу прощения, но я ничего не могу понять!
I apologize, but I can understand nothing! |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2259
|
Posted: Thu Mar 19, 2015 7:06 pm Post subject: |
|
|
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 |
|
|
sasha_1973
Joined: 30 Jul 2013 Posts: 58
|
Posted: Thu Mar 19, 2015 7:18 pm Post subject: |
|
|
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 |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2259
|
Posted: Thu Mar 19, 2015 7:47 pm Post subject: |
|
|
Yes. |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 970
|
Posted: Fri Mar 20, 2015 9:50 am Post subject: |
|
|
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 |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5905 Location: Holland
|
Posted: Fri Mar 20, 2015 10:25 am Post subject: |
|
|
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 |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2259
|
Posted: Fri Mar 20, 2015 12:32 pm Post subject: |
|
|
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 |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5905 Location: Holland
|
Posted: Fri Mar 20, 2015 1:20 pm Post subject: |
|
|
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 |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2259
|
Posted: Fri Mar 20, 2015 2:09 pm Post subject: |
|
|
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"
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 |
|
|
sasha_1973
Joined: 30 Jul 2013 Posts: 58
|
Posted: Fri Mar 20, 2015 2:13 pm Post subject: |
|
|
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 |
|
|
sasha_1973
Joined: 30 Jul 2013 Posts: 58
|
Posted: Fri Mar 20, 2015 2:31 pm Post subject: |
|
|
Огромное СПАСИБО всем за помощь!
Может объясните простыми словами, что надо сделать для работы исходника?
Many thanks to all for the help!
Maybe explain with simple words what it is necessary to make? |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5905 Location: Holland
|
Posted: Fri Mar 20, 2015 2:58 pm Post subject: |
|
|
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 |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2259
|
Posted: Fri Mar 20, 2015 3:20 pm Post subject: |
|
|
As long the SS is output:
Code: | CONFIG PORTB.2=OUTPUT |
the pin-value is "don't care", so that's not necessary:
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 |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5905 Location: Holland
|
Posted: Fri Mar 20, 2015 3:35 pm Post subject: |
|
|
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 |
|
|
|