Hi all,
I am interfacing C8051F120 Silabs microcontroller for one of my application. Description of the Application:
Data Acquisition and Controlling.16 bit ADC and DAC are connected to C8051F120 uC Via SPI.I need to acquire data from the Battery using ADC and Control the Battery(Charge/Discharge) using DAC.
I am not seeing Clock out on SCK pin.(I have checked using Oscilloscope).
Here is my Code.(The code is for ADC)
#include <c8051F120.h> #include <stdio.h> #define ADC_CH0 0x87 #define ADC_CH1 0xC7 #define ADC_CH2 0x97 #define ADC_CH3 0xD7 #define ADC_CH4 0xA7 #define ADC_CH5 0xE7 #define ADC_CH6 0xB7 #define ADC_CH7 0xF7 sbit CS_ADC1=P0^5; sbit BUSY1=P3^0; #ifndef BYTE #define BYTE unsigned char #endif #ifndef UINT #define UINT unsigned int #endif void Reset_Sources_Init (void); void OSCILLATOR_Init (void); void PORT_Init (void); //void UART0_Init (void); void SPI0_Init (void); void Init_Device (void); // The following functions save and restore SFRPAGE: void SPI_Write (UINT address, BYTE value); BYTE SPI_Read (UINT address); void adc_convert (UINT); unsigned char adcresult=0; unsigned char adc_lowbyte=0,adc_highbyte=0; void Reset_Sources_Init() { WDTCN = 0xDE; WDTCN = 0xAD; } void Oscillator_Init() { int i = 0; SFRPAGE = CONFIG_PAGE; OSCXCN = 0x67; for (i = 0; i < 3000; i++); // Wait 1ms for initialization while ((OSCXCN & 0x80) == 0); CLKSEL = 0x01; OSCICN = 0x00; } void Port_IO_Init() { SFRPAGE = CONFIG_PAGE; XBR0 = 0x07; XBR1 = 0x14; XBR2 = 0xC4; P0MDOUT = 0x35; P1MDOUT = 0x71; P2MDOUT = 0x73; P3MDOUT = 0x0F; SFRPAGE = CONFIG_PAGE; P5MDOUT = 0xFF; P6MDOUT = 0xFF; P7MDOUT = 0xFF; } void SPI0_Init() { SFRPAGE = SPI0_PAGE; SPI0CFG = 0x40; SPI0CN = 0x0D; SPI0CKR = 0xDC; } void Init_Device (void) { Reset_Sources_Init (); OSCILLATOR_Init (); Port_IO_Init (); SPI0_Init (); } void ADC_Write (UINT channel) { BYTE save_sfrpage = SFRPAGE; SFRPAGE = SPI0_PAGE; // Writing a byte to the EEPROM is a five-step operation. // Step1: Set the Write Enable Latch to 1 CS_ADC1 = 0; // Step1.1: Activate Slave Select SPI0DAT = channel; // Step1.2: Select channel while (!SPIF); // Step1.3: Wait for end of transfer SPIF = 0; // Step1.4: Clear the SPI intr. flag CS_ADC1 = 1; // Step1.5: Deactivate Slave Select //Delay_us (1); // Step1.6: Wait for at least // T_NSS_DISABLE_MIN SFRPAGE = save_sfrpage; } BYTE ADC_Read () { BYTE value; BYTE save_sfrpage = SFRPAGE; SFRPAGE = SPI0_PAGE; // Reading a byte from the ADC is a three-step operation. // Read the value returned CS_ADC1 = 0; SPI0DAT = 0; // Dummy write to output serial clock while (!SPIF); // Wait for the value to be read SPIF = 0; CS_ADC1 = 1; // Deactivate Slave Select //Delay_us (1); value = SPI0DAT; // Store EEPROM value in local var. SFRPAGE = save_sfrpage; return value; } void adc_convert (UINT adc_Ch) { ADC_Write(adc_Ch); while(BUSY1==1); if(BUSY1==0) { adc_highbyte=ADC_Read (); adc_lowbyte=ADC_Read (); } } void main(void) { Init_Device(); SFRPAGE = SPI0_PAGE; while(1) { adc_convert (ADC_CH0 ); } }
I am not able analyze the problem.Can somebody suggest me to solve my problem.
Thanks and Regards,
Y.Viswanath.