View previous topic :: View next topic |
Author |
Message |
petros047
Joined: 14 Mar 2012 Posts: 84
|
Posted: Mon Feb 27, 2017 9:34 pm Post subject: little help please with hard spi and tpic8101 ic |
|
|
Hello
I would like a little help, I am trying to initialise the tpic8101 ic ,knock sensor interface ic, but with out luck
I have try with noss=0 and also with external cs drive from pind5 and delay according the datasheet of the tpic8101 again with out luck.
It is my first time who I try to communicate with spi so maybe I am wrong in my program
$Regfile="m1284pdef.dat"
$Crystal=16000000
$hwstack=40
$swstack=16
$framesize=32
DIM FREQ AS BYTE
DIM GAIN AS BYTE
DIM CH1 AS BYTE
DIM BPASS AS BYTE
DIM TC AS BYTE
FREQ = &B01000101 'CRYSTALL 6MHZ
GAIN = &B10001110 '1 DB
CH1 = &B11100000
BPASS = &B00100111 '6.37KHZ
TC = &B11001010 '100NS
Waitms 1400
CONFIG SPI = HARD,INTERRUPT=OFF,DATA_ORDER = MSB,MASTER = YES,POLARITY = HIGH , PHASE = 0 ,CLOCKRATE = 4 ,NOSS = 0
SPIINIT
CONFIG PIND.6 = OUTPUT 'INT/HOLD
CONFIG PIND.5 = OUTPUT 'CS
start:
RESET PORTD.PD6
WAITUS 15
RESET PORTD.PD5
WAITUS 10
SPIOUT FREQ,1
SET PIND5
WAITUS 10
SET PIND6
WAITUS 10
RESET PORTD.PD6
WAITUS 15
RESET PORTD.PD5
WAITUS 10
SPIOUT GAIN,1
SET PIND5
WAITUS 10
SET PIND6
WAITUS 10
RESET PORTD.PD6
WAITUS 15
RESET PORTD.PD5
WAITUS 10
SPIOUT CH1,1
SET PIND5
WAITUS 10
SET PIND6
WAITUS 10
RESET PORTD.PD6
WAITUS 15
RESET PORTD.PD5
WAITUS 10
SPIOUT BPASS,1
SET PIND5
WAITUS 10
SET PIND6
WAITUS 10
RESET PORTD.PD6
WAITUS 15
RESET PORTD.PD5
WAITUS 10
SPIOUT TC,1
SET PIND5
WAITUS 10
SET PIND6
WAITUS 10
END
Here is the datasheet in page 7 is the spi config
http://www.ti.com/lit/ds/symlink/tpic8101.pdf
Thanks for any help
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Mon Feb 27, 2017 10:12 pm Post subject: |
|
|
No matter whether NOSS is set, for master mode either the SS-pin needs to be configured as output (level is a don't care then), or if SS set to input, it has to be pulled high. |
|
Back to top |
|
|
petros047
Joined: 14 Mar 2012 Posts: 84
|
Posted: Mon Feb 27, 2017 10:55 pm Post subject: |
|
|
thank you for the answer I already have config the pin to out i read other thread to this forum and i read the tip.
CONFIG SPI = HARD,INTERRUPT=OFF,DATA_ORDER = MSB,MASTER = YES,POLARITY = HIGH , PHASE = 0 ,CLOCKRATE = 4 ,NOSS = 0
SPIINIT
config pinb.4 = output 'ss
CONFIG PIND.6 = OUTPUT 'INT/HOLD
CONFIG PIND.5 = OUTPUT 'CS |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Tue Feb 28, 2017 9:31 am Post subject: |
|
|
petros047 wrote: | I already have config the pin to out |
As the shown code in this thread does not care about SS and my magic ball is in repair, I was not able to know.
It's your duty as the one seeking for help to show your actual code, respectively to update it.
As I'm talking about code, if you'd have the courtesy to use code-tags and some code-formatting, it would not look that plain ugly.
Some comments would be nice also.
Beside that, you do not want what your code actually does here:
Code: | SET PIND5
'...
SET PIND6 |
Why Pin at all? Pin is input register, Port output, and PIND5/6 simply is a constant from the dat-file, which in this case is interpreted as register number and thus the nonsense is out in full force.
Well, I've checked, the commands actually aren't ignored and do something, but not at all what's supposedly desired.
Last edited by MWS on Tue Feb 28, 2017 9:39 am; edited 1 time in total |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
|
Back to top |
|
|
petros047
Joined: 14 Mar 2012 Posts: 84
|
Posted: Tue Feb 28, 2017 10:44 am Post subject: |
|
|
Thanks a lot for the help. I realy must finish this project.
I will paste the code with some commends later
I have check the status for pind6 and pind5 and seems that work But i will try and with port word
What I do is simple according to tpic8101 datasheet
First I drive low the int/hold pin ,pind6
Wait a little 10ns as datasheet write
then i drive low the cs ,pind5
wait again 10ns
after that i send spi , spiout
drive high the cs
wait 10ns
then go to next command with cs low etc
so the program looks like
int/hold ,low
delay
cs ,low
delay
command
cs , high
delay
cs ,low
delay
command
cs,high
delay
.
.
.
.
at finish in/hold drive to high
I have try and with hardware ss
I also try to change the int/hold in each command
It is my first project with spi
so i am little confuse
here are some specs of tpic8101 spi
ƒSPI SPI frequency 5 MHz
t1 Time from CS falling edge to SCLK rising edge 10 ns
t2 Time from CS falling edge to SCLK falling edge 80 ns
t3 Time for SCLK to go high 60 ns
t4 Time for SCLK to go low 60 ns
t5 Time from last SCLK falling edge to CS rising edge 80 ns
t6 Time from SDI valid to falling edge of SCLK 60 ns
t7 Time for SDI valid after falling edge of SCLK 10 ns
t8 Time after CS rises until INT/HOLD to go high 8 ns
t9 Time between two words for transmitting 170 ns
t10 Time for SDO valid after SDI on bus, at VDD = 5 V and load = 20 pF 40 ns
Figure 1. Serial Peripheral Interface (SPI) |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Tue Feb 28, 2017 12:47 pm Post subject: |
|
|
petros047 wrote: | I have check the status for pind6 and pind5 and seems that work But i will try and with port word |
If that works you have different code than you showed, as:
translates to
Back-translated it would read:
translates to
Back-translated it would read:
Sure I know, what you want to do, as I've read the circuits data sheet, while you miss the very basics how to ask a forum for help and actually get the desired support.
Absolute minimum is to show your latest updated code, so it's possible to check and fix the errors.
It is surely not acceptable to have a description of code, when the code itself is available.
Maybe I should have used more direct words and simply have told you that SET PIND6 is utter nonsense.
And btw., the way you try to discuss or solve problems is just not what I consider as expedient, so I'll pull out here.
Your urge for success "I realy must finish this project." seems to me exactly the opposite how you approach it and that won't work. |
|
Back to top |
|
|
petros047
Joined: 14 Mar 2012 Posts: 84
|
Posted: Tue Feb 28, 2017 1:04 pm Post subject: |
|
|
Ok I paste my update code tonight and fix this errors
sorry for my phrase , realy must finish this project,But in March i wait tuner for my rx7 and i would like to have digital knock monitor
Also I forget to mention that I build the project in raster I dont know if that is problem for crystal freq or spi data.
Thank you for your time. |
|
Back to top |
|
|
petros047
Joined: 14 Mar 2012 Posts: 84
|
Posted: Wed Mar 01, 2017 12:32 am Post subject: |
|
|
Here is the update code
I try all the combinations and still not work
$Regfile="m1284pdef.dat"
$Crystal=16000000
$hwstack=40
$swstack=16
$framesize=32
DIM FREQ AS BYTE
DIM GAIN AS BYTE
DIM CH1 AS BYTE
DIM BPASS AS BYTE
DIM TC AS BYTE
FREQ = &B01000101 'CRYSTALL 6MHZ
GAIN = &B10010100 '0.73 DB
CH1 = &B11100000
BPASS = &B00100111 '6.37KHZ
TC = &B11000011 '55US
Waitms 1400
config portb.4 = output 'ss
CONFIG PortD.6 = OUTPUT 'INT/HOLD
CONFIG PortD.5 = OUTPUT 'CS
CONFIG SPI = HARD,INTERRUPT=OFF,DATA_ORDER = MSB,MASTER = YES,POLARITY = LOW , PHASE = 0 ,CLOCKRATE = 4,NOSS = 1
SPIINIT
start:
RESET PORTD.6 ' DRIVE LOW THE INT/HOLD PIN
WAITUS 15
RESET PORTD.5 'DRIVE LOW THE CS PIN
WAITUS 15 'WAIT 15 NS
SPIOUT FREQ,1 'SEND COMMAND
WAITUS 80 'WAIT 80NS
SET PORTD.5 'SET HIGH CS
WAITUS 180 'WAIT FOR NEXT COMMAND
'SET PORTD.6
'WAITUS 10
RESET PORTD.6
WAITMS 15
RESET PORTD.5
WAITUS 15
SPIOUT GAIN,1
WAITUS 80
SET PORTD.5
WAITUS 180
'SET PORTD.6
'WAITUS 10
RESET PORTD.6
WAITMS 15
RESET PORTD.5
WAITUS 15
SPIOUT CH1,1
WAITUS 80
SET PORTD.5
WAITUS 170
'SET PORTD.6
'WAITUS 10
RESET PORTD.6
WAITMS 15
RESET PORTD.5
WAITUS 15
SPIOUT BPASS,1
WAITUS 80
SET PORTD.5
WAITUS 170
'SET PORTD.6
'WAITUS 10
RESET PORTD.6
WAITMS 15
RESET PORTD.5
WAITUS 15
SPIOUT TC,1
WAITUS 80
SET PORTD.5
WAITUS 10
SET PORTD.6 |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
|
Back to top |
|
|
petros047
Joined: 14 Mar 2012 Posts: 84
|
Posted: Wed Mar 01, 2017 10:18 pm Post subject: |
|
|
Thank you for your reply and for your code ,incuding tips
unfortunately didnt work yet for some reason i take 5v out no matter what freq I give in input
I try also to your code to reset the int/hold at the begining and after all the commands set it again
I try with noss:1,0 and with high,low polarity
I add only 1us for delay between cs and command and after the command.
Maybe I have to try it in pcb and not in raster maybe I loose spi commands
Thanks for help |
|
Back to top |
|
|
petros047
Joined: 14 Mar 2012 Posts: 84
|
Posted: Sat Mar 04, 2017 3:09 pm Post subject: |
|
|
Finally solved I post the complete working code so if someone want to drive this ic can use it
The code from EDC , thank you
Code: | $regfile = "m1284pdef.dat"
$crystal = 16000000
$hwstack = 40
$swstack = 16
$framesize = 32
Config Submode = New 'first write a sub then use it in code
Dim Freq As Byte : Freq = &B01000101 'CRYSTALL 6MHZ
Dim Gain As Byte : Gain = &B10010100 '0.73 DB
Dim Ch1 As Byte : Ch1 = &B11100000
Dim Bpass As Byte : Bpass = &B00100111 '6.37KHZ
Dim Tc As Byte : Tc = &B11000011 '55US
Config Portb.4 = Output : Spi_ss Alias Portb.4 : Set Spi_ss
Config Portd.6 = Output : Int_hold Alias Portd.6 : Set Int_hold
Config Portd.5 = Output : Cs_pin Alias Portd.5 : Set Cs_pin
Config Spi = Hard , Interrupt = Off , Data_order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 1
Spiinit
Sub Send(byval Value As Byte)
Reset Int_hold
waitus 1 'need some delay before cs drive low
Reset Cs_pin
waitus 1 'delay before send the command
Spiout Value , 1
waitus 1 'delay before drive high cs
Set Cs_pin
End Sub
'sub is ready
'now program start
Call Send(freq)
Call Send(gain)
Call Send(ch1)
Call Send(bpass)
Call Send(tc)
Set Int_hold
Do
Set Int_hold 'You have to drive high and low the in/hold in order to integrate the input signal and take the output active
Waitus 1500 '
Reset Int_hold
Waitus 1500
Loop
End 'this is important to stop the program |
My code work too but is complete mess |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Sat Mar 04, 2017 11:40 pm Post subject: |
|
|
@petros047
- please use the code tags when posting code. _________________ / Kim |
|
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
|
|