I think that's the idea. Thanks for the link. I hope I can get this thing working.....
I think that's the idea. Thanks for the link. I hope I can get this thing working.....
There is also this article that i made;
http://www.picbasic.co.uk/forum/cont...P-PBP-MSSP-ASM
Thanks and Regards;
Gadelhas
Thanks for the info. It helped a little but I'm nowhere closer now than I was on Friday. Not one CAN frame received, nor was one sent. Part of my problem is that I don't completely understand the register settings listed in the datasheet. I keep reading it but it's not 100% clear so I'm sure my settings in the code aren't going to work. Can you (or anyone else) take a look at this and let me know where my mistakes are? I'm sure there are plenty
Code:DEFINE OSC 20 ' REGISTERS AND PINOUT ( 1 = IN; 0 = OUT ) ' ================================================================ '76543210 '76543210 TRISA = %11011111: PORTA = %00000000 TRISB = %00000000: PORTB = %00000001 TRISC = %00010000: PORTC = %00000000 TRISD = %00000000: PORTD = %00000000 TRISE = %00000000: PORTE = %00000000 ADCON0 = %00000000 ADCON1 = %00000000 ADRESH = %00000000 ADRESL = %00000000 CMCON = %00000000 SSPSTAT = %00000000 'I'M A LITTLE LOST WITH THE SSPSTAT AND SSPCON1 SSPCON1 = %00110000 ' VARIABLES AND CONSTANTS '============================================================================== TXBNCTRL var byte TXBNSIDH var byte TXBNSIDL VAR BYTE TXBNDLC VAR BYTE TXBNDM7 VAR BYTE TXBNDM6 VAR BYTE TXBNDM5 VAR BYTE TXBNDM4 VAR BYTE TXBNDM3 VAR BYTE TXBNDM2 VAR BYTE TXBNDM1 VAR BYTE TXBNDM0 VAR BYTE B0 VAR BYTE B1 VAR BYTE B2 VAR BYTE B3 VAR BYTE B4 VAR BYTE B5 VAR BYTE B6 VAR BYTE B7 VAR BYTE B7 = TXBNDM7 ' 8TH BYTE OF DATA FRAME B6 = TXBNDM6 ' 7TH BYTE OF DATA FRAME B5 = TXBNDM5 ' 6TH BYTE OF DATA FRAME B4 = TXBNDM4 ' 5TH BYTE OF DATA FRAME B3 = TXBNDM3 ' 4TH BYTE OF DATA FRAME B2 = TXBNDM2 ' 3RD BYTE OF DATA FRAME B1 = TXBNDM1 ' 2ND BYTE OF DATA FRAME B0 = TXBNDM0 ' 1ST BYTE OF DATA FRAME 'THE PIC MUST ENABLE THE CANINTE.TXINE BIT TO CHANGE THE INTERRUPT FLAG 'THE PIC MUST CLEAR THE TXBNCTRL.TXREQ BIT BEFORE WRITING TO THE TRANSMIT BUFFER ' ALIAS & MODIFIERS ' ================================================================ CS VAR PORTB.4 SCLK VAR PORTC.3 SDI VAR PORTB.0 SDO VAR PORTC.7 SENDLED VAR PORTA.5 'LED TO INDICATE THE PROGRAM IS IN THE SENDING ROUTINE MAINLED VAR PORTE.2 'LED TO INDICATE THE PROGRAM IS IN THE MAIN ROUTINE ' START OF PROGRAM '================================================================================ START: TOGGLE MAINLED 'LED INDICATING THE 18F4550 IS IN THE MAIN ROUTINE PAUSE 100 GOSUB SENDCANDATA 'CAN DATA IS ABOUT TO BE SENT......OR WE COULD ONLY WISH...... GOTO START ' SEND CAN DATA SECTION '=============================================================================== SENDCANDATA: PAUSE 50 TOGGLE SENDLED ' LED FOR DEBUGGING LOW CS ' CS PIN IS HELD LOW IN ORDER TO TRANSMIT DATA TXBNDLC = %00000111 ' DATA LENGTH. THIS IS FOR 8 BYTES. TXBNCTRL = %00001011 ' THE TXBNCTRL IS A REGISTER THAT DETERMINES THE CONDITIONS UNDER WHICH THE MESSAGE WILL BE TRANSMITTED. SEE DATA SHEET FOR DESCRIPTION. TXBNSIDL = %11100000 ' STANDARD IDENTIFIER BITS TXBNSIDH = %11111111 ' NOT REALLY SURE WHAT MICROCHIP WANTS HERE. IT JUST STANDARD IDENTIFIER BITS? B0 = $0 'DATA IN BYTE 1 B1 = $01 'DATA IN BYTE 2 B2 = $03 'DATA IN BYTE 3 B3 = $06 'DATA IN BYTE 4 B4 = $08 'DATA IN BYTE 5 B5 = $0A 'DATA IN BYTE 6 B6 = $0C 'DATA IN BYTE 7 B7 = $0E 'DATA IN BYTE 8 IF TXBNCTRL.3=1 OR TXBNCTRL.5=1 OR TXBNCTRL.4=1 THEN GOTO SENDCANDATA 'THERE WAS AN ERROR, TRY AGAIN. HIGH CS ' DATA TRANSMISSION IS COMPLETE. PUT CS LINE BACK TO 1. PAUSE 1000 RETURN
Hi,
As far as I can see there's nothing in your code that actually sends any data anywhere. In the SENDCANDATA you pull the CS line low, then you assign some values to a couple of variables, then you pull CS line high again. There's nothing to actually shift any data out of the PIC using either SHIFTOUT/SHIFTIN or the MSSP module.
Is there any chance you've looked at some code for a PIC with a built in CAN tranceiver? Is that perhaps where the TXBNDLC etc variables are coming from? If so, then those are probably registers for that particular PICs internal CAN tranceiver and simply creating variables with the same name will obviously not get anything out of your 2550 and into an external CAN tranceiver.
/Henrik.
I was thinking the same thing last night about sending data but I really don't know how the SPI function works. Here is an excerpt from the MCP2515 data sheet (stand alone CAN IC) where I got the TXBNDLC variable from:
![]()
Yeah, but that register is in the MCP2515 - you're only assigning values to variables in the PIC, there's currently nothing that transfers the data TO the register in the MCP2515.
Look at the SPI section of the datasheet for the MCP2515, under Write instruction it saysThen, looking at table 12-1 we can see that the Write instruction is (in binary) 00000010 or 2 in decimal. As you can see in your screenshot from the datasheet the adress of the TXBnDLC register(s) in the MCP2515 is $35, $45 and $55 respectively (apparently there's three of them, I haven't read enough yet to understand exactly what they do).The Write instruction is started by lowering the CS pin. The Write instruction is then sent to the MCP2515 followed by the address and at least one byte of data.
So to set the first of the TXBnDLC registers you need to shift out the WriteCommand (2), the adress ($35) and the actual data (7). The SPI section of the datasheet also tells us the device supports mode 0,0 and 1,1 and the timing diagram shows that it expects (and sends) MSB first. So, using SHIFTOUT the above would look something likeThe example I linked to earlier and the article gadelhas wrote shows you how to set up and use the MSSP module.Code:INCLUDE "modedefs.bas" Write_Cmd CON %00000010 ' Value for the Write Command TXB1DLC CON $35 ' Adress of the 1st TXBnDLC register in the MCP2515 LOW CS SHIFTOUT DataPin, ClkPin, MSBFIRST, [Write_Cmd, TXB1DLC, 7] HIGH CS
/Henrik.
Henrik,
You've made it a little clearer for me, thanks. I'm going to work with this today to see if I can get it to work. Something is strange with the demo boards I've received from Microchip. I can't erase the chip and even blinking an LED can be a task. I'm not even sure if the program I'm compiling is even getting to the 18F4550 at certain times. When I make the same circuit on a breadboard it doesn't give me any problems so I may have two issues at the same time, which makes things even more difficult.
Chris
Bookmarks