Autor Tema: Problemas PIC32MX575F256H  (Leído 3367 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado fantabuloso

  • PIC10
  • *
  • Mensajes: 24
Problemas PIC32MX575F256H
« en: 01 de Diciembre de 2011, 20:04:43 »
Hola Amigos, les escribo porque quiero hacerles una consulta y quería ver si me pueden ayudar, el problema es el siguiente: estoy realizando pruebas con mi nuevo ICD3 y resulta que tengo algunos inconvenientes con mi código, si debugueo el código y no coloco ciertos breakpoints, hay pines de mi pic que no cambian el estado, si le coloco los breakpoints los tomo y el programa funciona casi normalmente.
Esta es la primera vez que trabajo con este micro, había probado unos ejemplos hace un tiempo en el develpment kit, pero ahora cuando paso a trabajar sobre el diseño de mi circuito me encuentro con estos problemas. Una vez detectado el inconveniente con el debug, asumí que quizas el problema era el debug en si x lo q trate de programar el pic, el icd3 me dice que se programo en forma correcta, pero el programa no corre, les dejo adjuntado el código que en su mayoria está sacado del libro de pic32 que se puede bajar en forma gratuita. Cualquir ayuda es bienvenida. Les detallo a continuación los breakpoints que debo colocar para que funcione, estan marcados con :5], que sería la carita en llamas jaja:

Código: [Seleccionar]
/*
** SEE Library test
*/
 
#pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF
#pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_1

#include <p32xxxx.h>
#include <plib.h>
#include <math.h>
#include "see.h"

#define SYS_FREQ (80000000L)
#define DESIRED_BAUDRATE    (115200)
#define FPB     80000000L

#define RESET   _RD1      
#define TRESET   _TRISD1    
#define PIN_A     _RB3    
#define TPIN_A   _TRISB3
#define PIN_B     _RD7    
#define TPIN_B   _TRISD7
#define PIN_C     _RD6
#define TPIN_C   _TRISD6
#define PIN_D     _RD5    
#define TPIN_D   _TRISD5  
#define PIN_E   _RB6      
#define TPIN_E   _TRISB6    
#define READY   _RF1      
#define TREADY   _TRISF1
#define PIN_F _RD8      
#define TPIN_F _TRISD8

void DelayUS(WORD us)
{
 DWORD start = _CP0_GET_COUNT();
 DWORD end = start + SYS_FREQ / 1000000 / 2 * us;
 if (end > start) while (_CP0_GET_COUNT() < end);
 else while (_CP0_GET_COUNT() > start || _CP0_GET_COUNT() < end);
}

void DelayMS(WORD ms)
{
 DWORD start = _CP0_GET_COUNT();
 DWORD end = start + SYS_FREQ / 1000 / 2 * ms;
 if (end > start) while (_CP0_GET_COUNT() < end);
 else while (_CP0_GET_COUNT() > start || _CP0_GET_COUNT() < end);
}

void initGRAL()
{
DDPCONbits.JTAGEN = 0;
AD1PCFG = 0xffff;
T1CON = 0x8030;        
   PR1 = 0xFFFF;

TRISB =   0x07C0;        
TRISC =   0xF000;        
    TRISD =   0x0F14;        
TRISE =   0x00FF;
TRISF =   0x0013;        
TRISG =   0x028C;

PORTB = 0;
PORTC = 0;
PORTD = 0;
//PORTE = 0;
PORTF = 0;
PORTG = 0;
}

void initSPI2( void)
{
    // init the SPI2 peripheral
    TRESET = 0;
TPIN_A = 0;
TPIN_B = 0;                  // make SSEE pin output
    TPIN_C = 0;
TPIN_D = 0;
TPIN_E = 1;
TREADY = 1;
TPIN_F = 1;
DelayUS(100);
 :5] RESET = 1;
PIN_B = 1;                   // de-select the Serial EEPROM
    PIN_C = 1;
PIN_D = 1;
PIN_A = 0;
SPI2ACON = 0x8920;         // enable the peripheral
    SPI2ABRG = 23;         // select clock speed
}

void initUART()
{
int pbClk;
pbClk=SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
OpenUART1(UART_EN, UART_RX_ENABLE | UART_TX_ENABLE, pbClk/16/DESIRED_BAUDRATE-1);
}

void initCLK( int samplerate)
{
OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);
OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, FPB/samplerate);
PR2 = FPB/samplerate-1;
mT2SetIntPriority(4);
mT2ClearIntFlag();
mT2IntEnable(1);
SetDCOC1PWM(PR2/2);
}

int writeSPI2( int i)
{
    SPI2ABUF = i;                  // write to buffer for TX
    while( !SPI2ASTATbits.SPIRBF); // wait for transfer complete
    return SPI2ABUF;               // read the received value
}

void __ISR(_TIMER_2_VECTOR, ipl4) T2Interrupt( void)
{
mT2ClearIntFlag();
}

main()
{
    int data;
unsigned char datin = 30;
unsigned char F_PIN_E = 0;
int i;

    // initialize the SPI2 port and CS to access the 25LC256
    
initGRAL();
initSEE();
initUART();
initSPI2();
initCLK(1000000);


    // main loop
 :5] putsUART1("*** UART Simple Application Example ***\r\n");
 :5] putsUART1("*** Type some characters and observe echo and RA7 LED toggle  ***\r\n");
 :5] putcUART1('a');
    while ( 1)
    {
datin++;
        // read current content of memory location
        data = readSEE( 16);

        // increment current value
        data++;         // <-set brkpt here

        // write back the new value
        writeSEE( 16, data);
putcUART1(datin);
        //address++;

if ((PIN_E == 1) && (F_PIN_E == 0))
{
PIN_A = 1;
for (i=0;i<10240;i++)
{
if (F_PIN_E != 0)
{
while (READY == 1);
}
DelayUS(1);
PIN_C = 0;
PIN_B = 1;
writeSPI2(0xffffffff);
writeSPI2(0xffffffff);
DelayUS(1);
PIN_C = 1;
DelayUS(1);
PIN_B = 0;
writeSPI2(0xffffffff);
writeSPI2(0xffffffff);
DelayUS(1);
PIN_B = 1;
while (READY == 0);
PIN_D = 0;
DelayUS(20);
PIN_D = 1;
F_PIN_E = 1;
}
PIN_A = 0;
}

if ((PIN_E == 0) && (F_PIN_E == 1))
{
F_PIN_E = 0;
}
    }
}

« Última modificación: 01 de Diciembre de 2011, 20:12:01 por fantabuloso »

Desconectado Suky

  • Moderador Local
  • DsPIC33
  • *****
  • Mensajes: 6758
Re: Problemas PIC32MX575F256H
« Respuesta #1 en: 01 de Diciembre de 2011, 21:05:20 »
Es medio un quilombo el código  :mrgreen: porque mezclas configuración de módulos escribiendo directamente en los registros sin ningun comentario y después utilizas las funciones de las librerias de C32.

A simple vista no se ve algún error, aunque para un cristal de 8MHz iría XTPLL o POSCMOD=XT, FNOSC=PRIPLL. Desde los PIC24 se coloca XT hasta 10MHz.

Después por aquí hay un par de ejemplos.


Saludos!
No contesto mensajes privados, las consultas en el foro

Desconectado fantabuloso

  • PIC10
  • *
  • Mensajes: 24
Re: Problemas PIC32MX575F256H
« Respuesta #2 en: 02 de Diciembre de 2011, 15:59:04 »
Gracias por responder Suky, hice borron y cuenta nueva, y arranque desde cero con tus ejemplos, por otro lado felicitaciones por la placa si la hubiera visto antes te hubiese comprado una, hasta ahora los que probé funcionan bien, salvo por un pequeño inconveniente que tuve con el ejemplo del rtcc, donde hay que sacarle la siguiente instrucción: SYSTEMConfigPerformance(GetSystemClock()); ya que no funciona con el clock corriendo a 80Mhz, pero si para 72MHz, aparentemente de acuerdo al foro de microchip.

Nos vemos y gracias nuevamente.  :-/

Desconectado Suky

  • Moderador Local
  • DsPIC33
  • *****
  • Mensajes: 6758
Re: Problemas PIC32MX575F256H
« Respuesta #3 en: 02 de Diciembre de 2011, 18:30:17 »

Guarda con la información que se lea sobre los PIC32, tiene que ser actualizada. Esto lo digo porque las primeras versiones solo trabajaban a 72 MIPS y el periférico hasta 36 MIPS, después se paso a 80MIPS y 80MIPS, y se actualizaron todas las funciones.

Por ejemplo, aquí las actualizaciones para el libro PIC32 de LDJ: http://www.exploringpic32.com/6.html


Saludos!
« Última modificación: 02 de Diciembre de 2011, 18:34:18 por Suky »
No contesto mensajes privados, las consultas en el foro


 

anything