向高手求助。小弟近日在使用dsPIC33F系列控制TI的AD芯片TLC3578,可是没有调出来。请问有谁用过这款芯片,在
单片机程序中如何处理?能否给出TLC3578的样例代码,或者讲解一下这块芯片如何配置,如何使用。附上小弟的程
序和TLC3578的手册。我确信SPI的通讯没有问题。请帮助小弟解决一下,非常感谢。
///////////////////////////////////////////////////////// /////CODE FOR TLC3578 //////////////////////////////// void main() { // Local variables definitions WORD tempAD; int tt; BYTE SS1;
//*******************Configure PLL prescaler, PLL postscaler, PLL divisor PLLFBD=38; // M=40 CLKDIVbits.PLLPOST=0; // N1=2 CLKDIVbits.PLLPRE=0; // N2=2 // Wait for Clock switch to occur // Clock switching to incorporate PLL __builtin_write_OSCCONH(0x03); // Initiate Clock Switch to Primary // Oscillator with PLL (NOSC=0b011) __builtin_write_OSCCONL(0x01); // Start clock switching while (OSCCONbits.COSC != 0b011); while(OSCCONbits.LOCK != 1);
//********OSC CLK init end************************************** LongTimer = 0; IO_setup(); SPI2_Init(); //Timer45_Init();
LED = 0;//LED ON;
////////////////////////////////////////////////////////////// // Initialize AD module tt = 10; ADCS = 0;//片选AD Nop(); SPI2BUF = 0xA000;//进入软编程模式_WRITER_CFR_MODE while(!SPI2STATbits.SPIRBF); SPI2STATbits.SPIROV = 0; tempAD = SPI2BUF; ADCS = 1; Nop(); Nop(); ADCS = 0; Nop(); tt = 10; SPI2BUF = 0xAA00; //单端输入,短采样时;00 for INT mode ,04 for EOC mode //SPI2BUF = 0xA800; // hardware default mode while(!SPI2STATbits.SPIRBF); tempAD = SPI2BUF; SPI2STATbits.SPIROV = 0; ADCS = 1;
//**************************************
while(1) { SADres = ReadAD(0X07); } } //************************Program main loop ends**************************
WORD ReadAD(BYTE CHx) { int tick; WORD AD_res,tmpad; //tick = 10; //CHx = 0x7000; ADCS = 0; Nop(); SPI2BUF = 0x7000; while(!SPI2STATbits.SPIRBF); //ADCS = 1; while(ADEOC); //tick = 10; //ADCS = 0; SPI2BUF = 0x0000; while(!SPI2STATbits.SPIRBF); AD_res = SPI2BUF; SPI2STATbits.SPIROV = 0; ADCS = 1; AD_res /=4; AD_res &= 0x3FFF; return AD_res; }
|