HOODEY
Super Member
- Total Posts : 580
- Reward points : 0
- Joined: 2005/02/08 06:06:31
- Status: offline
pic18f spi
I have a pic interfaced with a RTC and tdc1000 altrasound chip. The rtc requires spi mode mode (1) and the tdc require mode 3. This is in a loop. However once i switch the spi back to mode 1 the rtc displays incorrect values. DS1305 is the real time clock. Once the spi mode is not changed the rtc has no issue. I find this extremely strange.
|
qhb
Superb Member
- Total Posts : 9999
- Reward points : 0
- Joined: 2016/06/05 14:55:32
- Location: One step ahead...
- Status: offline
Re: pic18f spi
2018/10/15 12:28:43
(permalink)
Are you using a CS line with both devices, and switching mode while both CS signals are idle?
|
NKurzman
A Guy on the Net
- Total Posts : 19144
- Reward points : 0
- Joined: 2008/01/16 19:33:48
- Location: 0
- Status: offline
Re: pic18f spi
2018/10/15 12:39:23
(permalink)
Are you disabling the MSSP before changing modes?
|
HOODEY
Super Member
- Total Posts : 580
- Reward points : 0
- Joined: 2005/02/08 06:06:31
- Status: offline
Re: pic18f spi
2018/10/15 20:25:11
(permalink)
I am using two different chip select lines. I am not disabling MSSP before switching modes. Before calling the tdc1000 routines i switch to mode 3 without disabling mssp and it has no issues. At one point i diasbled mssp and call the spi init routine again with mode 1. Same result. When I comment out the mode change the tdc fails but the rtc is happymad: ; PORTB,0 output SPI Chip Select tdc1000 ; PORTE,0 ouput dS1305 chip enable
call Usart_Init
movf RCREG,W ; Clear Interrupt flag may have been set before movf RCREG,W ; Clear Interrupt flag may have been set before movf RCREG,W ; Clear Interrupt flag may have been set before bcf PIR1, RCIF
call setDateAndTime
bsf INTCON, RBIE ;EnABLE PORT B INTERRUPTS ;Enable peripheral Interrupts so USART can received data from bsf INTCON, GIE ;Enable global Interrupts bsf INTCON, PEIE
emailsentloop:
call read_clock ; think this clears any interrupt flags as well as reading the time
; bsf SSPCON1,CKP ; bsf SSPSTAT,CKE
movlw d'10' call Long_Delay
call inittdc1011 call performtdcmeasurement bcf PORTB,3 ;Put TDC1011 to sleep
movlw d'40' call Long_Delay
bsf PORTD,0 ; Enable esp8266 will not conflict with rtc as rtc already set earlier rtc use serial comms with terminal window call setupESP8266 call sendemail bcf PORTD,0 ;Put ESP8266 to sleep
; bcf OSCCON,IDLEN ;Enable sleep mode. ; sleep ; nop ; nop
goto emailsentloop
post edited by HOODEY - 2018/10/15 20:37:06
|
qhb
Superb Member
- Total Posts : 9999
- Reward points : 0
- Joined: 2016/06/05 14:55:32
- Location: One step ahead...
- Status: offline
Re: pic18f spi
2018/10/15 20:40:25
(permalink)
Are you using B3 and D0 as your CS lines? The TDC1011 uses an active low CS, and I suspect the ESP8266 does too, but you are driving your pins the other way round (active high). (And BCF PIR1,RCIF is pointless, that flag is read-only.)
|
jack@kksound
code tags!
- Total Posts : 3227
- Reward points : 0
- Joined: 2014/05/14 10:03:19
- Location: 0
- Status: offline
Re: pic18f spi
2018/10/16 07:35:44
(permalink)
Also use LATx instead of PORTx for single bit outputs.
|
HOODEY
Super Member
- Total Posts : 580
- Reward points : 0
- Joined: 2005/02/08 06:06:31
- Status: offline
Re: pic18f spi
2018/10/16 16:49:45
(permalink)
PORTB,3 is the enable button of the tdc1000. I bring it high when making a measurement then pull it low when done. PORTD,0 goes to the ch_pd pin. i hold it low until i am ready to send an email. PORTE,0 is the ds1305 enable pin..active high PORTB,0 is the tdc1000 chip select active low. STILL NO JOY emailsentloop:
call read_clock ; think this clears any interrupt flags as well as reading the time
bcf RTC_CE bcf SSPCON1,SSPEN ; SSP Disable
nop nop nop nop
bsf SSPCON1,CKP bsf SSPSTAT,CKE
bsf SSPCON1,SSPEN ; SSP Enable
movlw d'10' call Long_Delay
call inittdc1011 call performtdcmeasurement bcf PORTB,3 ;Put TDC1011 to sleep
movlw d'40' call Long_Delay
bsf PORTD,0 ; Enable esp8266 will not conflict with rtc as rtc already set earlier rtc use serial comms with terminal window call setupESP8266 call sendemail bcf PORTD,0 ;Put ESP8266 to sleep
; bcf OSCCON,IDLEN ;Enable sleep mode. ; sleep ; nop ; nop
bcf SSPCON1,SSPEN ; SSP Disable
nop nop nop nop
bcf SSPCON1,CKP bsf SSPSTAT,CKE
bsf SSPCON1,SSPEN ; SSP Enable
nop
post edited by HOODEY - 2018/10/16 16:51:37
|
qhb
Superb Member
- Total Posts : 9999
- Reward points : 0
- Joined: 2016/06/05 14:55:32
- Location: One step ahead...
- Status: offline
Re: pic18f spi
2018/10/16 17:26:01
(permalink)
I can't see your code controlling PORTB,0 anywhere. It is very frustrating trying to diagnose code when you don't post the important bits.
|
HOODEY
Super Member
- Total Posts : 580
- Reward points : 0
- Joined: 2005/02/08 06:06:31
- Status: offline
Re: pic18f spi
2018/10/16 20:03:11
(permalink)
FIinally got it working. Datasheet is very misleading. Datasheet says rtc should not be able to operate in mode 0 . I switch to mode 0 for rtc then to mode 3 for tdc then back to mode 0.
post edited by HOODEY - 2018/10/17 05:58:34
|
Danno
Super Member
- Total Posts : 289
- Reward points : 0
- Joined: 2005/09/07 10:12:10
- Status: offline
Re: pic18f spi
2018/10/24 16:17:40
(permalink)
Which datasheet is misleading?
|
HOODEY
Super Member
- Total Posts : 580
- Reward points : 0
- Joined: 2005/02/08 06:06:31
- Status: offline
Re: pic18f spi
2018/10/30 10:27:29
(permalink)
|
jack@kksound
code tags!
- Total Posts : 3227
- Reward points : 0
- Joined: 2014/05/14 10:03:19
- Location: 0
- Status: offline
Re: pic18f spi
2018/10/30 10:37:15
(permalink)
HOODEY ds1305.
Maybe post the parts you feel are misleading, someone may be able to clarify?
|