CAN code for PIC 18f258
CAN code for PIC 18f258
I'm working with the CAN module on the pic 18f258 chip, and I'm wondering how to do a multi-register read or write. I want to be able to fill a struct or array of size 13bytes and write those bytes directly to registers TXBnCON through TXBnD7. Any suggestions on how I can do this? Better yet, do you have code written for the CAN module? The only CAN code that came with my mcc18 library was for the SPI CAN chip 2510.
No trees were harmed in the posting of this message. However, a large number of electrons were terribly inconvenienced.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: CAN code for PIC 18f258
Hello
No im afraid we do not currently have code to enable the onboard CAN registers. Hopefully Flowcode will be able to perform this soon. There is no multi register read or write as far as I can tell you will have to write each register value one at a time.
No im afraid we do not currently have code to enable the onboard CAN registers. Hopefully Flowcode will be able to perform this soon. There is no multi register read or write as far as I can tell you will have to write each register value one at a time.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: CAN code for PIC 18f258
Is there some way I can set up a pointer to the TXBnCON location and then increment it as I go along? Or are the registers in the wrong part of memory for that?
No trees were harmed in the posting of this message. However, a large number of electrons were terribly inconvenienced.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: CAN code for PIC 18f258
Hello
Yes im sure this can be done however im not sure how it would be acheived on the mcc18 compiler. There should be a compiler manual which will detail things like pointers and addresses.
However if you wanted to make life easier for your self you could just assign the values by writing directly to the registers.
Eg
TXBnCON = 0x00;
Yes im sure this can be done however im not sure how it would be acheived on the mcc18 compiler. There should be a compiler manual which will detail things like pointers and addresses.
However if you wanted to make life easier for your self you could just assign the values by writing directly to the registers.
Eg
TXBnCON = 0x00;
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: CAN code for PIC 18f258
That's easier in one way, but it makes for messy code when you've got three potential transmission buffers, plus two receive buffers, which take up 13 individual registers each. That's an extra 65+ lines of code, which could be downsized into 2 for-loops if I could use pointers for the registers.
No trees were harmed in the posting of this message. However, a large number of electrons were terribly inconvenienced.
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Re: CAN code for PIC 18f258
Could you resort to index addressing using the INDF and FSR registers in embedded assembly code? Alternatively, you could create a "write_reg" macro (or in-line function) in C that takes 2 parameters (address and value) which writes the "value" to the register at location "address".