Soy nuevo con el entorno PIC.
Quiero enviar una secuencia de 32 bits en un bucle utilizando SPI de PIC32MZ2048EFH064. Voy a enviar estos 32 bits a dos LP55281 ( enlace ) en cascada a la luz 8 RGB led . Mi intención es usar este LP55281 como registros de desplazamiento y, cuando se envíen todos estos 32 bits, encender todos los LED simultáneamente por PWM. Es posible hacer eso? Estoy probando mi idea, pero ningún led está encendido y no tengo instrumentos de medición:
HereismyPICconfiguration:/PIC32MZ2048EFH064ConfigurationBitSettings//'C'sourcelineconfigstatements//DEVCFG3//USERID=NoSetting#pragmaconfigFMIIEN=OFF//EthernetRMII/MIIEnable(RMIIEnabled)#pragmaconfigFETHIO=ON//EthernetI/OPinSelect(DefaultEthernetI/O)#pragmaconfigPGL1WAY=ON//PermissionGroupLockOneWayConfiguration(Allowonlyonereconfiguration)#pragmaconfigPMDL1WAY=ON//PeripheralModuleDisableConfiguration(Allowonlyonereconfiguration)#pragmaconfigIOL1WAY=ON//PeripheralPinSelectConfiguration(Allowonlyonereconfiguration)#pragmaconfigFUSBIDIO=ON//USBUSBIDSelection(ControlledbytheUSBModule)//DEVCFG2#pragmaconfigFPLLIDIV=DIV_8//SystemPLLInputDivider(8xDivider)#pragmaconfigFPLLRNG=RANGE_34_68_MHZ//SystemPLLInputRange(34-68MHzInput)#pragmaconfigFPLLICLK=PLL_FRC//SystemPLLInputClockSelection(FRCisinputtotheSystemPLL)#pragmaconfigFPLLMULT=MUL_128//SystemPLLMultiplier(PLLMultiplyby128)#pragmaconfigFPLLODIV=DIV_32//SystemPLLOutputClockDivider(32xDivider)#pragmaconfigUPLLFSEL=FREQ_24MHZ//USBPLLInputFrequencySelection(USBPLLinputis24MHz)//DEVCFG1#pragmaconfigFNOSC=SPLL//OscillatorSelectionBits(SystemPLL))#pragmaconfigDMTINTV=WIN_127_128//DMTCountWindowInterval(Window/Intervalvalueis127/128countervalue)#pragmaconfigFSOSCEN=ON//SecondaryOscillatorEnable(EnableSOSC)#pragmaconfigIESO=ON//Internal/ExternalSwitchOver(Enabled)#pragmaconfigPOSCMOD=OFF//PrimaryOscillatorConfiguration(Primaryoscdisabled)#pragmaconfigOSCIOFNC=OFF//CLKOOutputSignalActiveontheOSCOPin(Disabled)#pragmaconfigFCKSM=CSECME//ClockSwitchingandMonitorSelection(ClockSwitchEnabled,FSCMEnabled)#pragmaconfigWDTPS=PS1048576//WatchdogTimerPostscaler(1:1048576)#pragmaconfigWDTSPGM=STOP//WatchdogTimerStopDuringFlashProgramming(WDTstopsduringFlashprogramming)#pragmaconfigWINDIS=NORMAL//WatchdogTimerWindowMode(WatchdogTimerisinnon-Windowmode)#pragmaconfigFWDTEN=ON//WatchdogTimerEnable(WDTEnabled)#pragmaconfigFWDTWINSZ=WINSZ_25//WatchdogTimerWindowSize(Windowsizeis25%)#pragmaconfigDMTCNT=DMT31//DeadmanTimerCountSelection(2^31(2147483648))#pragmaconfigFDMTEN=ON//DeadmanTimerEnable(DeadmanTimerisenabled)//DEVCFG0#pragmaconfigDEBUG=OFF//BackgroundDebuggerEnable(Debuggerisdisabled)#pragmaconfigJTAGEN=ON//JTAGEnable(JTAGPortEnabled)#pragmaconfigICESEL=ICS_PGx1//ICE/ICDCommChannelSelect(CommunicateonPGEC1/PGED1)#pragmaconfigTRCEN=ON//TraceEnable(TracefeaturesintheCPUareenabled)#pragmaconfigBOOTISA=MIPS32//BootISASelection(BootcodeandExceptioncodeisMIPS32)#pragmaconfigFECCCON=OFF_UNLOCKED//DynamicFlashECCConfiguration(ECCandDynamicECCaredisabled(ECCCONbitsarewritable))#pragmaconfigFSLEEP=OFF//FlashSleepMode(FlashispowereddownwhenthedeviceisinSleepmode)#pragmaconfigDBGPER=PG_ALL//DebugModeCPUAccessPermission(AllowCPUaccesstoallpermissionregions)#pragmaconfigSMCLR=MCLR_NORM//SoftMasterClearEnablebit(MCLRpingeneratesanormalsystemReset)#pragmaconfigSOSCGAIN=GAIN_2X//SecondaryOscillatorGainControlbits(2xgainsetting)#pragmaconfigSOSCBOOST=ON//SecondaryOscillatorBoostKickStartEnablebit(Boostthekickstartoftheoscillator)#pragmaconfigPOSCGAIN=GAIN_2X//PrimaryOscillatorGainControlbits(2xgainsetting)#pragmaconfigPOSCBOOST=ON//PrimaryOscillatorBoostKickStartEnablebit(Boostthekickstartoftheoscillator)#pragmaconfigEJTAGBEN=NORMAL//EJTAGBoot(NormalEJTAGfunctionality)//DEVCP0#pragmaconfigCP=OFF//CodeProtect(ProtectionDisabled)
Aquíelcódigo:
#include<xc.h>#definesystem_clock1024000000ul#defineFCY(system_clock/4)#include<stdlib.h>#include<stdint.h>//Configurationbits#include"bitconfig.h"
#include <stdio.h>
void oscill(void)
{
//Oscillator configuration
OSCCONbits.NOSC = 0b111; // Internal Fast RC (FRC) Oscillator divided by FRCDIV<2:0> bits (FRCDIV).
OSCCONbits.CLKLOCK = 0b0; // Clock and PLL selections are not locked and may be modified.
OSCTUNbits.TUN = 0b000000; // Center frequency; FRC oscillator runs at nominal frequency (8 MHz).
SPLLCONbits.PLLMULT = 0b1111111; // System PLL Multiplier bits x128 system_clock 1024Mhz, Fcy = 256 Mhz
SPLLCONbits.PLLICLK = 0b1; // FRC is selected as the input to the System PLL
SPLLCONbits.PLLRANGE = 0b101; // System PLL Frequency Range Selection bits 34-64 Mhz
}
void init_spi(void)
{
//Configuration SPI-1- MODULE
PORTDbits.RD1 = 0; // Set SCK1 as output pin
RPD2R = 0b0101; // Set SDO1 (0101) to pin RPDR (PPS output)
RPD9R = 0b0101; // Set SS1 (0101) to pin RPDR (PPS output)
SDI1R = 0b0010; // Set SDI1 to pin RPF4 (0000) (PPS input)
SPI1CONbits.FRMEN = 0; // Framed SPI support is disabled (normal mode)
SPI1CONbits.MSSEN = 1; // Slave select SPI support is enabled. The SS pin is automatically driven during transmission in Master mode
SPI1CONbits.ENHBUF = 1; // Enhanced Buffer mode is enabled
SPI1CONbits.ON = 1; // SPI/I2S module is enabled
SPI1CONbits.DISSDO=0; // SDO1 pin is controlled by the module
SPI1CONbits.CKE = 1; // Transmit occurs on transition from active to Idle clock state
SPI1CONbits.CKP = 0; // Idle state for clock is a low level
SPI1CONbits.MSTEN = 1; // Master Mode Enable bit
SPI1STATbits.SPITBF = 1; // Transmit is not yet started, SPITXB is full
SPI1STATbits.SPIRBF = 1; // SPI Receive Buffer Full Status bit
SPI1CONbits.MODE16=1; // Communication is word/byte (16 bits)
}
void SPI_write(int data) {
SPI1STATbits.SPIRBF = 0;
SPI1BUF = data;
while( !SPI1STATbits.SPIRBF); // Wait until transfer is complete
}
int i;
int main(void)
{
for(i = 1; 0 <= i; i --)
{
SPI_write(0b0010101010101010); // Send two times to both LP55281
}
¿Qué está mal? Estoy seguro de que varias cosas. Necesito ayuda.
Gracias.