Datasheet and register question


Closed Thread
Results 1 to 22 of 22

Hybrid View

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

    Default Datasheet and register question

    This is probably a basic question for most of you but I can't quite figure it out. I have a register that needs to be set, lets say INEEDSLEEP. The addresses are 80h, 90h, 100h. My questions are:

    1. If the data sheet says it's bits <3:0>, why are there only three addresses when it covers four bits?

    2. Do you put the exact same values into all of the addresses?

    When I've used more basic registers, I just use something like INEEDSLEEP = %00010100. Maybe I just never noticed it but I don't remember ever having to put values into three different addresses for one value.

    I'll start with this and see if someone can get it through my thick skull.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    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.

  3. #3
    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

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    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.

  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

    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.

  6. #6
    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.

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