View previous topic :: View next topic |
Author |
Message |
remix
Joined: 05 Sep 2013 Posts: 13
|
Posted: Mon May 12, 2014 9:29 pm Post subject: problem with send single variable to spi bus |
|
|
hi
i want send a single data to spi bus
but slave cant read from master
this code working with long ,int,byte,word but just not working in single
please help me
MASTER CODE:
Code: |
$regfile = "m32def.dat"
$crystal = 8000000
$baud = 19200
$hwstack = 32
$swstack = 10
$framesize = 40
'----------
Config Lcd = 20 * 4
Config Lcdpin = Pin , Rs = Portc.0 , E = Portc.1 , Db4 = Portc.2 , Db5 = _
Portc.3 , Db6 = Portc.4 , Db7 = Portc.5
Config Spi = Hard , Interrupt = Off , Data Order = Lsb , Master = Yes , Polarity = High , Phase = 0 , Clockrate = 128
Config Single = Scientific , Digits = 5
Dim B As Byte
Dim A(10) As Single
Spiinit
A(1) = 111.22
B = 5
Do
Spiout A(1) , B
Loop
|
SLAVE CODE :
Code: |
$regfile = "m32def.dat"
$crystal = 8000000
$baud = 19200
$hwstack = 32
$swstack = 10
$framesize = 40
'----------
Config Lcd = 20 * 4
Config Lcdpin = Pin , Rs = Portc.0 , E = Portc.1 , Db4 = Portc.2 , Db5 = _
Portc.3 , Db6 = Portc.4 , Db7 = Portc.5
Config Spi = Hard , Interrupt = Off , Data Order = Lsb , Master = No , Polarity = High , Phase = 0 , Clockrate = 128
Config Single = Scientific , Digits = 5
Dim B As Byte
Dim A(10) As Single
Spiinit
B = 5
Do
Spiin A(1) , B
Locate 1 , 1
Lcd A(1)
Loop
|
(BASCOM-AVR version : 2.0.7.7 ) |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Tue May 13, 2014 7:48 am Post subject: Re: problem with send single variable to spi bus |
|
|
remix wrote: |
Code: |
A(1) = 111.22
B = 5
Do
Spiout A(1) , B
Loop
|
|
You shift out 5 bytes, but a single is 4 bytes long. _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
remix
Joined: 05 Sep 2013 Posts: 13
|
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Tue May 13, 2014 8:24 pm Post subject: |
|
|
Read this http://wiki.mcselec.com/bavr/CONFIG_SINGLE
Maybe You dont need this in the master uC. Try send without this option.
Also You can convert it to String or if you have eg. 2 digits after decimal point multiply this by 100 and after all calculations /100..
..and look in samples for spi and spi-slave - I see some diferents in config but if this work on Word and Long maybe this is nomather
Code: |
Dim A(10) As Single
Dim Help as Long ' or something that contain your single*100
A(1) = 111.22
A(1) = 111.22 * 100
Help = A(1)
Spiout Help...
|
|
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Wed May 14, 2014 9:23 am Post subject: |
|
|
first, show us your code that works with longs. _________________ Mark |
|
Back to top |
|
|
kmswong
Joined: 10 Apr 2006 Posts: 8
|
Posted: Fri May 23, 2014 4:01 pm Post subject: |
|
|
Example in help!
Dim A(10) As Byte
Config Spi = Soft , Din =Pinb.0 , Dout =Portb.1 , Ss =Portb.2 , Clock =Portb.3
Spiinit
Spiout A(1), 4 'write 4 bytes a(1), a(2) , a(3) and a(4)
End |
|
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
|
|