Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Help needed with Arduino SPI setup..

Options
  • 18-08-2009 8:03pm
    #1
    Registered Users Posts: 2,234 ✭✭✭


    I'm trying to interface an Arduino with a Holtek T9200B to generate DTMF tones.

    The interface is SPI and I will be using this Arduino tutorial on an SPIDigitalPot and this Arduino SPI code reference..

    At the moment I think I am fine with setting up the circuit.. The real problem comes with setting up the SPI clock to run at 3.579535 Mhz

    The code below shows how to set the clock but the bold is something I have honestly no clue about..
    Spi.mode((1<<CPOL) | (1 << CPHA)); // set SPI mode 3
    or
    Spi.mode((<<SPR0)); // set SPI clock to system clock / 16


    I'm thinking its some kind of bit manipulation or something like that but I have no clue. I'd appreciate it if somebody could identify this and point me in the direction of a quick primer to help me get over the line.

    Thanks Guys...


Comments

  • Registered Users Posts: 3,945 ✭✭✭Anima


    Yeah its bit manipulation. An example would be

    [PHP]1 << 3[/PHP]

    That means start with "0001" then shift it to the left 3 times. Which gives you "1000" in binary.

    So CPOL and CPHA are just convienent ways of defining the correct number to shift across, rather than having magic numbers everywhere.

    Edit: as below.


  • Registered Users Posts: 368 ✭✭backboiler


    Little oversight there: 1 << 3 is 8, not 256 (0x100). It's a binary bit shift, not hex. 1 << 8 is 0x100.

    In OP, "Spi.mode((<<SPR0));" also makes no sense, there should be a number before the << operator.

    The "|" is a bitwise OR operator used to combine indivdual bit patterns in this case, so if for example CPOL has a value of 2 and CPHA is 5 the value passed to Spi.mode is 0x24, 0b00100100 (bits 2 and 6 set).


  • Registered Users Posts: 6,752 ✭✭✭zg3409


    You mighe be interested in going to the Dublin Arduino group:

    http://www.tog.ie/category/arduino/

    They may or may not have more answers

    Dan


Advertisement