Jason,
I'm trying to use the new sys_mcspi.h header file which you provided.
I have a simple test program I adapted from some example code that toggles a gpio pin which I monitor with a scope.
I use the toggle rate seen on the scope to determine whether phaseBit is zero or not.
(the code is below)
The code writes a 1 to the phase control bit in the SPI config register.
Then it reads it back into the phaseBit variable.
I figure if it writes a 1 it should read back a 1.
Trouble is it's always reading back 0.
The code does what is expected if I force a 1 or 0 into phaseBit
Not sure what I'm doing wrong. (remember I'm new to PRU work)
Do does the code have to do something to enable access to the SPI registers?
Thanks,
Kirk
/*
* Based on the examples distributed by TI
*
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
#include <pru_cfg.h>
#include <pru_ctrl.h>
#include <sys_mcspi.h>
#include "resource_table_empty.h"
volatile register uint32_t __R30;
volatile register uint32_t __R31;
void main(void)
{
volatile uint32_t gpio;
volatile uint32_t phaseBit;
/* Clear SYSCFG[STANDBY_INIT] to enable OCP master port */
CT_CFG.SYSCFG_bit.STANDBY_INIT = 0;
// attempt to write an SPI configuration bit and read it back
CT_MCSPI0.CH0CONF_bit.PHA = 0x1;
phaseBit = CT_MCSPI0.CH0CONF_bit.PHA;
// by forcing phaseBit to 0 or 1 here I get the expected toggle rate below
// phaseBit = 1;
/* Toggle GPO pins TODO: Figure out which to use */
gpio = 0x000F;
// if phaseBit is non-zero toggle fast, otherwise toggle slow
while (1) {
__R30 ^= gpio;
if(phaseBit == 0)
{
__delay_cycles(1000000); // toggle at approx 100Hz
}
else
{
__delay_cycles(500000); // toggle at approx 200Hz
}
}
}