Datasheet and register question


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Datasheet and register question

    Hi Christopher,
    It would be nice if you linked to the datasheet you're looking at but due to your other currently 'active' threads I suspect it's the MCP2515 we're talking about? If not then this answer may not apply.

    1) There are three INEEDSLEEP registers, one at adress $80, one at $90 and one at $100. Judging by the other register names in the MCP2515 the description of the register in the datasheet would likely be something like INEEDSLEEPn where n is the number of the register. 0,1,2 or perhaps 1,2,3. There are 8bits en each register but you're interested in the lower 4bits <3:0> of each register.

    2) It depends on what INEEDSLEEP does and what YOU want to do really. Since I don't know CAN or the MCP2515 (if that's what we're really talking about here) I'm going to try a stupid example. If the chip wasn't a CAN driver but a say PWM chip with three output channels. Then you'd have three dutycycle registers in the chip. The functionality and operation of the registers would be exactly equal so instead of describing it three times in the datasheet the might show it DUTYn (at adresses $10, $20, $30 or whatever) where n is either 0,1 or 2 for the three different channels.

    Now, if you wanted to set the dutycycle of all three channels to 0 would you write 0 to all three registers? YES of course. If you then wanted to set the dutycycle of channel 1 to 50 would you write 50 to all three registers? NO of course not, you'd write 50 to DUTY1, which is at address $20 in the external chip. If it was in the PIC then the actual address would be of less interest because the compiler would include a file (think of it like sort of a phonebook) with register names and their addresses, so you could access it directly by its name (DUTY1).

    As I said, a stupid example but it's the best I can do without reference to the actual part and actual register. I hope it makes some sense though.

    /Henrik.

  2. #2
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: Datasheet and register question

    Min forre flickvan (mycket vakra) var Svensk och jag prata lite Svenska! It's been years but I still remember a little, although there may be spelling mistakes

    Anyhow, I started this thread for the datasheet question because it was more of a generic question but yes, I am asking about the MCP2515. Here are the two things I can't understand:

    1. Page 21. For TXBnDm it gives a number of address values and they are looking for eight different numbers. I've found that the .asm files and the C files provided help out a little bit but do I need to put each of the TXBnDm numbers (0-7) in a different address or do I just assign a value to them in the code like TXB1Dm = $FF or is it written TXBnDm7 = $FF?

    2. I'm learning about the bit modify instruction but it isn't completely clear. I don't understand how to code the higher and lower order address bits. As an example, on page 61 I am having trouble understanding how to program TXBnSIDL and TXBnSIDH.

    Thanks,

    Chris

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Datasheet and register question

    Hej Christopher,
    Din svenska är helt OK!

    1) The MCP2515 has three transmit buffers (ie it's to these buffers you write the data to be sent out on the CAN bus). Each of these transmit buffers consists of 8 bytes. The first transmit buffer starts at $36 and ends at $3D. So the first byte of the first buffer is at address $36 and would be called TXB0D0 (Transmit Buffer 0 DataByte 0). The first byte of the second buffer would be at address $46 and would be called TXB1D0 (Transmit Buffer 1 DataByte 0) and so on.

    You can't simply do TXB0D0 = $FF because, once again, the register is not in the PIC, you'll have to write to that register using either SHIFTOUT or the MSSP module like we discussed in one of the other threads. Ie, to load TXB0D0 with $FF you'd do
    Code:
    SHIFTOUT DataPin, ClkPin, MSBFirst, [2, $36, $FF]   ' 2=Write Instruction, $36=adress of TXB0D0 regsiter, $FF=Data to be written to that register
    Now, you can obviously create CONstants to the various registers and commands, like
    Code:
    WriteCmd CON 2
    TXB0D0 CON $36
    SHIFTOUT DataPin, ClkPin, MSBFirst, [WriteCmd, TXB0D0, $FF]

    2) The register map on page 61 shows the address of all the registers in the device. TXBnSIDL and TXBnSIDH are Transmit Buffer Standard Identifier (whatever that is) register and since there are three Transmit buffers there are three TXNnSIDL and TXBnSIDH registers (again, n would be 0,1 or 2 for the three individual registers "coupled" to each transmit buffer.

    So, looking at the table on page 61, you can see that the four high order bits of the address are in the columns and the four low order bits are in the rows. For TXB0SIDL you'll get 0011 for the high order bits and 0010 for the low order bits. Combing these give you %00110010 which is the same as $32 - which, if you look at the description for the TXBnSIDL register (page 20) matches what they say IS the address of TXB0SIDL.

    So, to write the value $12 to TXB0SIDL you'd do
    Code:
    SHIFTOUT DataPin, ClkPin, MSBFirst, [2, $32, $12]   '2=WriteInstruction, $32= Adress of register, $12=Data to write.
    In the register map all register which are allowed to be manipulated by the BitModify instruction are shaded. The TXBnSIDL registers are not shaded and can not be modified using the BitModify instruction.

    /Henrik.

  4. #4
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: Datasheet and register question

    Thanks for the help Henrik. I still don't understand it. I've been trying for the past four days and I can't get my variables set up correctly. I've been looking at code on here and other places on the internet and I'm more confused than I was before - most of them are in C. The datasheet seems really confusing to me. I think I've wasted more than 100 hours so far.

  5. #5
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: Datasheet and register question

    I have a hammer in one hand and the 18F4550, along with the MCP2515 are on my table. It would really provide a lot of stress relief.

    I'm going to scrap this and just go with an 18F with CAN built in.

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: Datasheet and register question

    The 4550 is quite commonly supported... not only that but the datasheets seem (to me) to be written properly...

    I've not played with CAN, however i (along with a lot of other people on here) know the 4550 very well...

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Datasheet and register question

    Hi Christopher,
    This may be moot if you've already decided to switch devices but it still seems to me like if you're missing one crucial point. You said that you can't get your variable set up correctly which variables are you talking about here and how do you set them? I don't mean to which values you set them but how do you actually assign your values - whatever value it might be - TO the variable?

    The reason I ask is because I still think you may be missing the point that in order for the MCP2515 to work you need to set IT up - ie assign values to the regsiters that are IN the MCP2515. The MCP2515 is an intelligent device, it's not like a MAX232 which has nothing to set up. When you say variables it sounds as if you're still trying to assign values to variables that you create in the PIC and that won't work.

    Are you using SHIFTOUT to write the values or do you use the MSSP module?

    If it was me I start by making a routine which write values to the MCP2515. Then I'd make a routine which reads values from the MCP2515 to verify that the write routine is working properly.

    Can you post some code of your current attempts?

    /Henrik.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts