Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

little help please with hard spi and tpic8101 ic

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

Bascom Member



Joined: 14 Mar 2012
Posts: 84

greece.gif
PostPosted: Mon Feb 27, 2017 9:34 pm    Post subject: little help please with hard spi and tpic8101 ic Reply with quote

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
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1944

blank.gif
PostPosted: Mon Feb 27, 2017 10:12 pm    Post subject: Reply with quote

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
View user's profile
petros047

Bascom Member



Joined: 14 Mar 2012
Posts: 84

greece.gif
PostPosted: Mon Feb 27, 2017 10:55 pm    Post subject: Reply with quote

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
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2132

netherlands.gif
PostPosted: Tue Feb 28, 2017 9:00 am    Post subject: Reply with quote

It's port not pin
Code:

config portb.4 = output 'ss
CONFIG PortD.6 = OUTPUT 'INT/HOLD
CONFIG PortD.5 = OUTPUT 'CS
 


Ps and the caps lock of your keyboards is stuck Very Happy

_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1944

blank.gif
PostPosted: Tue Feb 28, 2017 9:31 am    Post subject: Reply with quote

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
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1944

blank.gif
PostPosted: Tue Feb 28, 2017 9:38 am    Post subject: Reply with quote

Evert Smile wrote:
It's port not pin
Code:

config portb.4 = output 'ss
CONFIG PortD.6 = OUTPUT 'INT/HOLD
CONFIG PortD.5 = OUTPUT 'CS
 

Using Config with the word Pin is equal to Port, see the help.
Back to top
View user's profile
petros047

Bascom Member



Joined: 14 Mar 2012
Posts: 84

greece.gif
PostPosted: Tue Feb 28, 2017 10:44 am    Post subject: Reply with quote

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
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1944

blank.gif
PostPosted: Tue Feb 28, 2017 12:47 pm    Post subject: Reply with quote

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:
Code:
SET PIND5
translates to
Code:
SBI       0x05,0

Back-translated it would read:
Code:
Set PortB.0

Code:
SET PIND6
translates to
Code:
SBI       0x06,0

Back-translated it would read:
Code:
Set PinC.0

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
View user's profile
petros047

Bascom Member



Joined: 14 Mar 2012
Posts: 84

greece.gif
PostPosted: Tue Feb 28, 2017 1:04 pm    Post subject: Reply with quote

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 Smile
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
View user's profile
petros047

Bascom Member



Joined: 14 Mar 2012
Posts: 84

greece.gif
PostPosted: Wed Mar 01, 2017 12:32 am    Post subject: Reply with quote

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
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 749

poland.gif
PostPosted: Wed Mar 01, 2017 1:40 pm    Post subject: Reply with quote

This is little interesting topic for me because I`m mechatronic Very Happy

After configuring port pins as outputs they still have their states - after reset this is low.
So after configuring pins you have Int_hold and Cs_pins in low state and chip listening for commands Very Happy

After configuring pins like Int_hold and Cs_pin should be set to High state.

Next thing - you should know that nanoseconds (ns) are not microseconds (us) Very Happy

I thik build one Sub for all these task is helpful.
All procedures which are repeated you should pack into some functions/subs

And at the end you should stop processor for executing if there is no more other code because it will start from the begining Very Happy
So try like that:

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
  Reset Cs_pin
   Spiout Value , 1
  Set Cs_pin
 Set Int_hold

End Sub

'sub is ready
'now program start

Call Send(freq)
Call Send(gain)
Call Send(ch1)
Call Send(bpass)
Call Send(tc)

End                                                         'this is important to stop the program

 
Back to top
View user's profile Visit poster's website
petros047

Bascom Member



Joined: 14 Mar 2012
Posts: 84

greece.gif
PostPosted: Wed Mar 01, 2017 10:18 pm    Post subject: Reply with quote

Thank you for your reply and for your code ,incuding tips Very Happy
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
View user's profile
petros047

Bascom Member



Joined: 14 Mar 2012
Posts: 84

greece.gif
PostPosted: Sat Mar 04, 2017 3:09 pm    Post subject: Reply with quote

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 Very Happy
Back to top
View user's profile
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Sat Mar 04, 2017 11:40 pm    Post subject: Reply with quote

@petros047

- please use the code tags when posting code.

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
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