Autor Tema: Escritura y lectura de datos SRAM dspic33f  (Leído 2818 veces)

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

Desconectado lidia

  • PIC10
  • *
  • Mensajes: 7
Escritura y lectura de datos SRAM dspic33f
« en: 14 de Junio de 2010, 07:33:20 »
Hola a todos!!!!

Necesitio almacenar en memoria las muestras de dos señales de audio captadas frame a frame, que luego debo leer completas para poder hacer el procesado de señal. Hasta ahora las estaba almacenando en la FLASH, pero había pensado usar una SRAM, ya que una vez realizados los cálculos no necesito estas señales para nada, aunque si necesitaría almacenar el resultado de dichas operaciones, supongo que en la propia FLASH o una EEPROM. Si pudierais recomendarme qué tipo de memoria usar, y en el caso de la SRAM ponerme algún ejemplito de cómo se accede a las direcciones.... sería perfecto.

Muchas gracias de antemano!!!!

Saludos!

Desconectado migsantiago

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8257
    • Sitio de MigSantiago
Re: Escritura y lectura de datos SRAM dspic33f
« Respuesta #1 en: 14 de Junio de 2010, 21:24:10 »
Hola

Talvez te sirva de poco, pero hay un ejemplo de manejo de SRAM por SPI en C30 con un PIC24. Talvez puedas modificarlo para tu dspic.

Está en la ayuda de C30:

Código: [Seleccionar]
#define USE_AND_OR
#include<p24fxxxx.h>
#include <string.h>
#include <spi.h>
#include <sram.h>

#if defined(__PIC24FJ128GA010__)
/*************** COFIGURATION **************************************
*    Watchdog Timer Disabled
*    Two Speed Start-up enabled
*    Oscillator Selection: HS oscillator ( 8MHz crystal on EXPLORER 16 Board )
*    Clock switching and clock monitor both enabled
********************************************************************/
_CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2)
_CONFIG2(IESO_OFF & FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_HS & FNOSC_PRIPLL)
#endif

unsigned char ReadVal;
unsigned char SRAMBuf[SRAM_PAGE_SIZE];        //Used to perform read/write operations from/to SRAM

void InitSRAM(void);

#define        SRAM_SCK                LATFbits.LATF6
#define        SRAM_MISO                PORTFbits.RF7
#define        SRAM_MOSI                LATFbits.LATF8

#define        SRAM_CS_TRIS            TRISFbits.TRISF2
#define        SRAM_SCK_TRIS            TRISFbits.TRISF6
#define        SRAM_MISO_TRIS            TRISFbits.TRISF7
#define        SRAM_MOSI_TRIS            TRISFbits.TRISF8


int main(void)
{
    unsigned char Cnt;

    InitSRAM();        //Initialize SRAM

    while(1)
    {
        //Select Page mode in SRAM
        SRAMWriteStatusReg(SRAM_PAGE_MODE);

        //Read Status Register
        ReadVal = SRAMReadStatusReg();

        //Write Byte operation
        //Write 0x28 to 0x1000 memory location of SRAM
        SRAMWriteByte(0x00,0x10,0x28);

        ReadVal = 0x00;
        //Read Byte operation
        //Read 0x1000 memory location of SRAM
        ReadVal = SRAMReadByte(0x00,0x10);
        //Page Write operation
        //Write 32bytes from SRAMBuf array to first page of SRAM
        for(Cnt = 0;Cnt<32;Cnt++)
        {
            SRAMBuf[Cnt] = (0xAA - Cnt);
        }

        SRAMWritePage(0x00,0x20,SRAMBuf);

        //Page Read operation
        //Read 32bytes from SRAMBuf array from first page of SRAM
        memset(SRAMBuf,0,sizeof(SRAMBuf));    //Reset SRAMBuf location to 0x00 value
        SRAMReadPage(0x00,0x20,SRAMBuf);

        //Sequential Write operation
        //Write 10bytes from SRAMBuf to SRAM starting from 0x1000 memory location
        memset(SRAMBuf,0,sizeof(SRAMBuf));    //Reset SRAMBuf location to 0x00 value
        for(Cnt = 0;Cnt<32;Cnt++)
        {
            SRAMBuf[Cnt] =(0x55-Cnt);
        }
        SRAMWriteSeq(0x10,0x10,SRAMBuf,10);

        //Sequential Read operation
        //Read 10bytes starting from 0x1010 memory location of SRAM and store it to SRAMBuf array
        memset(SRAMBuf,0,sizeof(SRAMBuf));    //Reset SRAMBuf location to 0x00 value
        SRAMReadSeq(0x10,0x10,SRAMBuf,10);
    }

}

void InitSRAM(void)
{

    SRAM_CS = 1;
    SRAM_SCK = 0;
    SRAM_CS_TRIS = 0;
    SRAM_SCK_TRIS = 0;
    SRAM_MISO_TRIS = 1;
    SRAM_MOSI_TRIS = 0;

    CloseSPI1();         /* Turn off SPI module 1 */
    OpenSPI1((SPI_CKE_ON|MASTER_ENABLE_ON|SEC_PRESCAL_1_1|PRI_PRESCAL_4_1),
              FRAME_ENABLE_OFF,SPI_ENABLE);

}

Desconectado lidia

  • PIC10
  • *
  • Mensajes: 7
Re: Escritura y lectura de datos SRAM dspic33f
« Respuesta #2 en: 15 de Junio de 2010, 04:14:22 »
Muchas gracias por responder!!!! :)

Ya tengo por dónde empezar!!!!


 

anything