Witam, przenoszę program, jak w temacie, pierwotnie uruchomiony na pic32mx360f512. Jak narazie nie rozwiązałem następujących problemów:
a) nie potrafię spowodować aby SPI1 startował z impulsem wyzwalającym w trybie framed slave mode. Pin wejścia SS1 przydzielony, impulsy na pinie widoczne na oscyloskopie, a transmisji przez SPI brak.
b)Łańcuchowanie aktywności DMA sprawia wrażenie jakoby oba DMA 0 i 1 startowały równocześnie, a nie zerowy startował jako następca pierwszego.
W powyższym programie procesor jest przetaktowany do 64MHz, ale opisane problemy nie ustępują dla taktowania dopuszczonego specyfikacją, ani gdy Fpb=Fck/2.
Pozdrawiam i poszę o poradę
a) nie potrafię spowodować aby SPI1 startował z impulsem wyzwalającym w trybie framed slave mode. Pin wejścia SS1 przydzielony, impulsy na pinie widoczne na oscyloskopie, a transmisji przez SPI brak.
b)Łańcuchowanie aktywności DMA sprawia wrażenie jakoby oba DMA 0 i 1 startowały równocześnie, a nie zerowy startował jako następca pierwszego.
#pragma config POSCMOD=XT, FNOSC=PRIPLL, FSOSCEN=OFF, IESO=OFF
#pragma config FPLLIDIV=DIV_2, FPLLMUL=MUL_16, FPLLODIV=DIV_1 //64MHz
#pragma config FWDTEN=OFF//, FPBDIV=DIV_2//, JTAGEN=OFF //, ICESEL=ICS_PGx1
#include <p32xxxx.h>
#include <plib.h>
#include <math.h>
Void Initialize (void){
ANSELA = 0;
ANSELB = 0; //all ports digital
TRISA = 0x00;
TRISB = 0x00;//84;//84-dodatkowe wymuszenie pinów jako wejscia
LATA = 0;
LATB = 0;// */
// fist stop dma and ISRs
SYSKEY = 0x12345678; // ensure syskey is locked
SYSKEY = 0xAA996655; // Write Key1 to SYSKEY
SYSKEY = 0x556699AA; // Write Key2 to SYSKEY
// Composite Video Out
SS1R = 4; //RPB7 = SS1 input
RPB8R = 3; //RPB8 = SDO1
RPB9R = 5; //RPB9 = OC3
// SD MC
RPA1R = 4; //RPA1 = SDO2
SDI2R = 4; //RPB2 = SDI2 // B15 = SCK2
// Audio PWM
RPB4R = 5; // OC1
RPB5R = 5; // OC2
// Relock the SYSKEY
SYSKEY = 0x0; // Write any value other than Key1 or Key2
} // initialize
#define VRES 200 // desired vertical resolution
#define HRES 256//256 // desired horizontal resolution pixel
//#define DOUBLE_BUFFER // comment if single buffering required
#define LINE_N 312 // number of lines in PAL frame
#define LINE_T 4096 // 4096Tpb clock in a line (64us)
// count the number of remaining black lines top+bottom
#define VSYNC_N 3 // V sync lines
#define VBLANK_N (LINE_N -VRES -VSYNC_N)
#define PREEQ_N VBLANK_N/2 // preeq + bottom blank
#define POSTEQ_N VBLANK_N -PREEQ_N // posteq + top blank
// definition of the vertical sync state machine
#define SV_PREEQ 0
#define SV_SYNC 1
#define SV_POSTEQ 2
#define SV_LINE 3
// timing for composite video horizontal state machine
#define PIX_T 8 // Tpb clock per pixel
#define HSYNC_T 300// 180 //300 // Tpb clock width horizontal pulse
#define BPORCH_T 660//340 //666 // Tpb clock width back porch
#define Home() { cx=0; cy=0;}
#define Clrscr() { clearScreen(); Home();}
#define AT( x, y) { cx = (x); cy =(y);}
int VMap1[ VRES*(HRES / 32)]; // image buffer
#ifdef DOUBLE_BUFFER
int VMap2[ VRES*(HRES / 32)]; // second image buffer
#endif
int *VA = VMap1; // pointer to the Active VMap
#ifdef DOUBLE_BUFFER
int *VH = VMap2;
#else
int *VH = VMap1;
#endif
volatile int *VPtr;
volatile short VCount;
volatile short VState;
// next state table
short VS[4] = {SV_SYNC, SV_POSTEQ, SV_LINE, SV_PREEQ};
// next counter table
short int VC[4] = {VSYNC_N, POSTEQ_N, VRES, PREEQ_N};
int zero[2] = {0x0f0f,0xf0f0};//{0xAA, 0x55};//{0,0}; //
short cx, cy; // <=========== dostawilem
void __ISR(_TIMER_3_VECTOR, ipl7SOFT) T3Interrupt(void)
{// advance the state machine
if (--VCount == 0) {
VCount = VC[ VState & 3];
VState = VS[ VState & 3]; }
// vertical state machine
switch (VState) {
case SV_SYNC: // 1
// vertical sync pulse
OC3R = LINE_T - HSYNC_T - BPORCH_T;
break;
case SV_POSTEQ: // 2
// horizontal sync pulse
OC3R = HSYNC_T;
break;
case SV_PREEQ: // 0
// prepare for the new frame
VPtr = VA;
break;
default:
case SV_LINE: // 3
// preload of the SPI waiting for SS (Synch high)
SPI1BUF = 0;//xAA559911;
// update the DMA0 source address and enable it
DCH0SSA = KVA_TO_PA((void*) VPtr);
// DmaChnSetTxfer(0, (void*) VPtr, (void *) & SPI1BUF, HRES / 8, 4, 4);
VPtr += HRES / 32;
DmaChnEnable(1);
break;
} //switch
// clear the interrupt flag
mT3ClearIntFlag();
} // T3Interrupt
void initVideo(void) {
// 1. init the SPI1 select framed slave mode to synch SPI with OC3
SpiChnOpen (1, SPICON_ON | SPICON_MSTEN | SPICON_MODE32, PIX_T);
//| SPICON_FRMEN | SPICON_FRMSYNC | SPICON_FRMPOL, PIX_T);
// 2. make SS1 a digital input // allready in initialize
// 3. init OC3 in single pulse, continuous mode
OpenOC3 (OC_ON | OC_TIMER3_SRC | OC_CONTINUE_PULSE, 0, HSYNC_T);
// 4. Timer3 on, prescaler 1:1, internal clock, period
OpenTimer3 (T3_ON | T3_PS_1_1 | T3_SOURCE_INT, LINE_T - 1);
// 5. init the vertical sync state machine
VState = SV_LINE;
VCount = 1;
// 6. init the active and hidden screens pointers
VA = VMap1;
#ifdef DOUBLE_BUFFER
VH = VMap2;
#else
VH = VA;
#endif
// 7. DMA 1 configuration back porch extension
DmaChnOpen (1, 1, DMA_OPEN_DEFAULT);
DmaChnSetEventControl(1, DMA_EV_START_IRQ_EN | DMA_EV_START_IRQ(_SPI1_TX_IRQ));
DmaChnSetTxfer(1, (void*) zero, (void *) & SPI1BUF, 8, 4, 4);
// 8. DMA 0 configuration image serialization
DmaChnOpen (0, 0, DMA_OPEN_DEFAULT);
DmaChnSetEventControl(0, DMA_EV_START_IRQ_EN | DMA_EV_START_IRQ(_SPI1_TX_IRQ));
DmaChnSetTxfer(0, (void*) VPtr, (void *) & SPI1BUF, HRES / 8, 4, 4);
// chain DMA0 to completion of DMA1 transfer
DmaChnSetControl(0, DMA_CTL_CHAIN_EN | DMA_CTL_CHAIN_DIR);
// 9. Enable Timer3 Interrupts
// set the priority level 7 to use shadow register set
mT3SetIntPriority( 7);
mT3IntEnable( 1);
} // initVideo
W powyższym programie procesor jest przetaktowany do 64MHz, ale opisane problemy nie ustępują dla taktowania dopuszczonego specyfikacją, ani gdy Fpb=Fck/2.
Pozdrawiam i poszę o poradę