Page 1 of 1

Problems with MSSP??

Posted: Fri Apr 08, 2005 12:24 pm
by clog
HI,
I am developing an interface using the LCD2041 and a 4x4 matrix keypad. The microcontroller I am using is a PIC16C774 and I am programming it with assembly. However, thus far, I have been unable to communicate with the LCD. I can see the change on the SCL and SDA lines through an oscilloscope, but the display maintains its blinking cursor with no changes. I am pretty new to all this, but I have looked through numerous topics on this forum and still have not found a solution. I am wondering if there are any known problem using the built in MSSP module.

I am using 10k pull-up resistors(I have tried 1k and 4.7k), currently I am only sending out the display address 0x5C and 0x41(letter A) but am not getting a response. I tried slowing down the bit rate, but same results as with 100kbits/s.

Any suggestions or information would be appreciated.

Cont...

Posted: Fri Apr 08, 2005 1:52 pm
by clog
Here is my i2c code using MSSP. So I am moving the address of the display into DEVADD and the data I want to send into DATAOUT then call MyI2COut.


MyI2COut
;SLEW RATE CONTROL
movlw B'00000000'
banksel SSPSTAT
movwf SSPSTAT ;slew rate disabled

banksel SSPCON
movlw B'00111000' ;Enable I2C master mode
movwf SSPCON
bsf SSPCON,SSPEN

banksel SSPCON2
movlw B'00001010' ;100kbit/s when device runs at 4MHz
movwf SSPADD
bsf TRISC,SDA ;Drive SDA high/ input
bsf TRISC,SCL ;Drive SCL high/ input
bsf SSPCON2,SEN ;send Start Condition
;Check for completion of I2C stat event




banksel SSPCON2
btfsc SSPCON2,SEN ;test start bit state
goto $-1 ;module busy so wait.




call SSPIF_Wait ;interrupt should be set so we need to wait.



;addressing the slave 0x5C with write "0" bit

banksel DEVADD
movf DEVADD,0 ;move the address into W
banksel SSPBUF
movwf SSPBUF ;transmit over the bus

call ACK_Wait

call SSPIF_Wait


banksel DATAOUT
movf DATAOUT, 0 ;move the transmitted byte into W
banksel SSPBUF
movwf SSPBUF ;tansmit over the bus

call ACK_Wait

call SSPIF_Wait

banksel SSPCON2
bsf SSPCON2,PEN ;send stop condition



banksel SSPCON2
btfsc SSPCON2,PEN
goto $-1

return

Posted: Fri Apr 08, 2005 2:39 pm
by Miles
Hi Clog,

Thank you for posting at Matrix Orbital forums. If you can email me at myero@matrixorbital.ca I'll send you an example of the I2C protocol with keypad functionality! :) It appears that the address in which you are sending is not correct...

Posted: Mon Apr 11, 2005 9:01 am
by clog
Thanks Miles.

Did you get my e-mail?

Posted: Mon Apr 11, 2005 10:21 am
by Tom
Hi Clog,

I have emailed you a sample. Another example can be found at http://www.lcdforums.com/forums/viewtop ... s&start=15 .

Best Regards,

Posted: Mon Apr 11, 2005 12:06 pm
by clog
I should get an acknowledge right? For both the address and the data going to the display. Right now, I am not getting one.

Posted: Mon Apr 11, 2005 1:30 pm
by Tom
You should always see an "ACK", if you have communications with the unit. Matrix Orbital units do not have the capability to NACK. The following link will give you more detail on I2C with Matrix Orbital units.

http://www.lcdforums.com/forums/viewtopic.php?t=910

I also sent you another email.

If you have anymore questions or concerns, please feel free to post.

Best Regards, :D

Posted: Mon Apr 11, 2005 3:47 pm
by clog
Thanks Tom. Sorry the snippet doesn't show me loading DEVADD register with 5C, but I do. Here is the whole code. Like I said all I am trying to do is establish communication and display 'A'.

list P=PIC16C774
#include <p16C774.inc>
__config (_CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _HS_OSC)
errorlevel -302 ;suppress bank warning

Freq equ 4 ;crystal frequency in MHz (4, 10, or 20)
Bank0RAM equ H'20' ;Start of Bank 0 RAM area
SCL equ 3
SDA equ 4

cblock Bank0RAM
;I2C variables
DEVADD ;bits <7:1> device address. bit 0 is R/_W bit, 0=write to the slave address, 1=read from slave
DATAOUT ;Data to be written into INTADD during a write
DATAIN ;Find the data in the DATAIN
;end of I2C variables
DELAY_ms
GenCount
endc

org 0x00 ;where the goto is in memory, 0 is power on reset location
reset
movlw 0x5C
movwf DEVADD
movlw 0x41
movwf DATAOUT

MyI2COut
;SLEW RATE CONTROL
movlw B'00000000'
banksel SSPSTAT
movwf SSPSTAT ;slew rate enabled for 100khz
bsf SSPSTAT,SMP ; Disable slew rate control, set for 100kHz

banksel SSPCON
movlw B'00111000' ;Enable I2C master mode
movwf SSPCON
bsf SSPCON,SSPEN

banksel SSPCON2
movlw B'00001001' ;100kbit/s when device runs at 4MHz
movwf SSPADD
bsf TRISC,SDA ;Drive SDA high when it is a input
bsf TRISC,SCL ;Drive SCL high when it is a input
bsf SSPCON2,SEN ;send Start Condition
;Check for completion of I2C stat event

banksel SSPCON2
btfsc SSPCON2,SEN ;test start bit state
goto $-1 ;module busy so wait.

call SSPIF_Wait ;interrupt should be set so we need to wait.



;addressing the slave 5C with write "0" bit

banksel DEVADD
movf DEVADD,W ;move the address with direction bit into W
banksel SSPBUF
movwf SSPBUF ;transmit over the bus

call ACK_Wait

call SSPIF_Wait


banksel DATAOUT
movf DATAOUT, W ;move the transmitted byte into W
banksel SSPBUF
movwf SSPBUF ;tansmit over the bus

call ACK_Wait

call SSPIF_Wait

banksel SSPCON2
bsf SSPCON2,PEN ;send stop condition



banksel SSPCON2
btfsc SSPCON2,PEN
goto $-1



call SSPIF_Wait

return

SSPIF_Wait
banksel PIR1 ;set register access to bank 0
btfss PIR1, SSPIF ;skip if interrupt is set
goto SSPIF_Wait
bcf PIR1, SSPIF ;clear interrupt
return

ACK_Wait
;wait for an acknowledgement

banksel SSPCON2 ;set register access to bank 1
btfsc SSPCON2, 6 ;wait for acknowledgement
goto $-1
return

end

Posted: Mon Apr 11, 2005 4:05 pm
by Tom
Try making a little looping program to scan through all the addresses.

Rookie mistake

Posted: Wed Apr 13, 2005 12:36 pm
by clog
So I got the display working with the expected address(0x5C). It turned out to be the wiring that caused the problem. I feel kind of silly, but I am glad it is working. Thanks for your help I will let you know if I have any other questions.

Posted: Wed Apr 13, 2005 12:56 pm
by Tom
Glad you got it working.

If you have anymore questions or concerns, please feel free to post.

Best Regards, :D