Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 19th May 2008, 02:51 PM   (permalink)
Default MSSP with 16F876A

I feel completely retarded not being able to figure out what went wrong. Here's the code, it's just meant to send a repeating pulse out of SDO by using the MSSP module in Master mode.

Code:
list p=16f876A
#include <p16f876a.inc>

main:		BSF STATUS,RP0
		MOVLW 0x07
		MOVWF ADCON1
		BCF TRISC,5
		BCF TRISC,3
		BSF TRISC,4
		BSF SSPCON,5
		BCF STATUS,RP0
ser:		BTFSS SSPSTAT,BF
		GOTO ser
		MOVLW 0x66
		MOVWF SSPBUF
		GOTO ser
		END
The first few lines make sure that all the ports on the device are digital (Lest I want to expand the code to somehow use PortA). I use the bit setting to set up the direction of the serial pins to what the datasheet says to use (Clear bit 5 and 3, set 4), and I set the SPI enable bit in SSPCON. (Switch back to Bank 0)

I check the SSPSTAT<BF> bit to check if the serial shift register is done outputting, goes back to wait for it if it's not ready, or puts 0x66 in to send if it is done. As far as the datasheet says, as soon as there is data in the SSPBUF, it's supposed to shift it out, but it just sits there with the pins high. I must've made an obvious mistake that someone can point out, right?
__________________
<-- Feel free to IM me for random chit-chat and PIC assembly talk
Adobe After Effects lets you save your work before it crashes, now THAT'S user-friendly.
ArtemisGoldfish is online now   Reply With Quote
Old 19th May 2008, 03:00 PM   (permalink)
Default

Don't you have to send something before you can get a buffer full condition and once you get BF then you need to read it to prevent a collision.

Mike.
Pommie is online now   Reply With Quote
Old 19th May 2008, 03:05 PM   (permalink)
Default

If I'm looking at it and it's 0 because the buffer is empty, it should work fine with the condition.
__________________
<-- Feel free to IM me for random chit-chat and PIC assembly talk
Adobe After Effects lets you save your work before it crashes, now THAT'S user-friendly.
ArtemisGoldfish is online now   Reply With Quote
Old 19th May 2008, 03:07 PM   (permalink)
Default

Quote:
Originally Posted by ArtemisGoldfish View Post
If I'm looking at it and it's 0 because the buffer is empty, it should work fine with the condition.
Won't it wait forever?

Mike.
Pommie is online now   Reply With Quote
Old 19th May 2008, 03:11 PM   (permalink)
Default

Hahah, now that you mention it, I maybe should've used BTFSC. I also noticed that I was trying to read from SSPSTAT in the wrong bank. I'll fix these and see what happens.
__________________
<-- Feel free to IM me for random chit-chat and PIC assembly talk
Adobe After Effects lets you save your work before it crashes, now THAT'S user-friendly.
ArtemisGoldfish is online now   Reply With Quote
Old 19th May 2008, 03:21 PM   (permalink)
Default

Quote:
Originally Posted by ArtemisGoldfish View Post
Hahah, now that you mention it, I maybe should've used BTFSC. I also noticed that I was trying to read from SSPSTAT in the wrong bank. I'll fix these and see what happens.
I don't think that will cure the problem. Try writing to SSPBUF, then wait for BF, then read SSPBUF, then loop.

Mike.
Pommie is online now   Reply With Quote
Old 19th May 2008, 03:33 PM   (permalink)
Default

Code:
list p=16f876A
#include <p16f876a.inc>

main:		BSF STATUS,RP0   ;Initializing stuff in Bank 1
		MOVLW 0x07
		MOVWF ADCON1
		BCF TRISC,5
		BCF TRISC,3
		BSF TRISC,4
		BSF SSPCON,5     ;Set the SSP Enable bit
		BCF STATUS,RP0  ;Back to Bank 0
ser:		CALL cond
		BTFSC 0x20,0
		GOTO ser
		MOVLW 0x66
		MOVWF SSPBUF
		GOTO ser
cond:		BSF STATUS,RP0
		MOVF SSPSTAT,W
		BCF STATUS,RP0
		MOVWF 0x20
		RETURN
		END
This time I use the cond routine to go into Bank 1, copy the SSPSTAT register to W, go back to Bank 0, and put W into a general purpose register. I BTFSC the BF bit to see if it's not set, if it's all fine, it goes and writes into SSBUF. In the simulator I'm using, it actually gets to writing 0x66 to SSPBUF, but for some reason, the simulator doesn't/can't properly execute the BSF SSPCON,5 instruction. (Using Oshonsoft's PIC Simulator) In the space where it usually says the instruction, when I step through, the BSF SSPCON,5 instruction just appears as "BSF". Could just be a problem with the simulator now, I'll have to test the program on the real hardware when I get my ICD2.
__________________
<-- Feel free to IM me for random chit-chat and PIC assembly talk
Adobe After Effects lets you save your work before it crashes, now THAT'S user-friendly.
ArtemisGoldfish is online now   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
stepper motor with 16f876a jay543_uk Micro Controllers 10 8th February 2008 08:05 PM
Pic 16f876a Prog. Problem JEFFxxx Micro Controllers 9 5th October 2006 09:45 PM
16F876A YAN-1 Micro Controllers 1 14th December 2005 08:56 AM
PWM module in the 16F876A YAN-1 Micro Controllers 3 23rd May 2005 12:08 AM
Need help programming the MSSP on the PIC16F877 avinsinanan Micro Controllers 1 20th August 2003 10:04 AM



All times are GMT. The time now is 04:45 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.