Gast
#3278398
Hallo, ich hätte hier ein Problem bei dem ich hoffe das mir irgendjemand damit etwas helfen könnte. Ich versuche den PIC24FJ128Ga010 mit einem AD Wandler von TI (TLC1514) zu verbinden. Jedoch bekomme ich aus meinem SDO noch nicht einmal bits heraus (Oszi hängt dran). Eine vermutung ist das ich die Pins falsch konfiguriert habe, doer an den komplett falschen pins bin. Ich verwende: SPI2 : RG6 SCK2 , RG7 SDI2 , RG8 SDO2 Ich habe schon das Forum hier durchwühlt, jedoch leider ohne erfolg... Schon einmal danke im Vorraus. Code: SPI.h #include <p24FJ128GA010.h> #define SPI2_CS TRISF #define SPI2_CS1 PORTFbits.RF2 void SPI2Init(void); int writeSPI2 (int data); int readSPI2(int data); main.c #include "SPI1.h" //#define SPI2_CS TRISF //#define SPI2_CS1 PORTFbits.RF2 #define WRITE_CFR 0xA000 // write CFR register followed by 12 bit data #define READ_CFR 0x9000 // read CFR register data show as SDO #define READ_SDO 0xE000 // FIFO read, FIFO contents shown as SDO #define A0 0x0000 #define SPI_MASTER 0x0120 #define SPI_ENABLE 0x8000 void SPI2Init(void) { //config SPI2 SPI2_CS = 0xff00; // set Port F as Output SPI2_CS1 = 1; // disable SPI2 CS1 SPI2CON1 = SPI_MASTER; SPI2STAT = SPI_ENABLE; } int writeSPI2( int data ) { SPI2BUF = data; // write to buffer for TX while(!SPI2STATbits.SPIRBF); // wait for transfer to complete return SPI2BUF; // read the received value } int readSPI2(int data) { SPI2BUF = data ; // write to buffer for TX while(!SPI2STATbits.SPIRBF); // wait for transfer to complete return SPI2BUF; // read the received value } void configADC(void) { short int cmd,cfr,cmdw,test; cmd = 0x0020; // config SPI2_CS1 = 0; // select the adc writeSPI2(0xA000); // Wake up the adc SPI2_CS1 = 1; // deselect the adc cmdw = WRITE_CFR | cmd; // form write cmd + config while (1) { SPI2_CS1 = 0; // select adc //writeSPI2(WRITE_CFR&cmd); writeSPI2(cmdw); // write cmd + config writeSPI2(READ_CFR); // write see cmd for config cfr = readSPI2(0); // receive config cfr = cfr & 0x0FFF; // only the last three bytes are necessary SPI2_CS1 = 1; // deselect adc if (cfr == cmd) // if config correct, break and return main break; } //SPI2_CS1 = 1; } void main (void) { int value[100],i; SPI2Init(); // Init SPI mode configADC(); // config the adc through SPI for(i=0; i<100; i++) // read the first 500 ad values { SPI2_CS1 = 0; // select adc writeSPI2(READ_SDO); // write see cmd for the FIFO value[i] = readSPI2 (0); // receive FIFO SPI2_CS1 = 1; // deselect adc } } mfg Christian
