Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
PIC18F4550 and ADC my connection MISO - MOSI
What is your ADC operating voltage level...
#pragma config PLLDIV = 1
#pragma config CPUDIV = OSC4_PLL6
#pragma config FOSC = INTOSC_HS
#pragma config USBDIV = 1
#pragma config IESO = OFF
#pragma config PWRT = OFF
#pragma config BOR = OFF
#pragma config VREGEN = OFF
#pragma config WDT = OFF
#pragma config WDTPS = 32768
#pragma config CCP2MX = ON
#pragma config PBADEN = OFF
#pragma config LPT1OSC = OFF
#pragma config MCLRE = ON
#pragma config STVREN = ON
#pragma config LVP = OFF
#pragma config ICPRT = OFF
#pragma config XINST = OFF
#pragma config DEBUG = OFF
#pragma config WRTD = OFF
Have you also face that problem?
How can I turn off USB
void spi_master_init ( void )
{
TRISC &= 0b00001111; // clear 7th bit keeping all other bits unchanged (SDO output)
TRISB &= 0b00001101; // clear 1th bit keeping all other bits unchanged (SCK output)
TRISA |= 0x20; // clearing 5th bit, SS as output
ADCON0 = 0x3C; // Disabling the ADC module which is multiplexed with SPI pins
ADCON1 = 0x0F; // Disabling the ADC module which is multiplexed with SPI pins
CMCON = 0x00; // Disabling the COMPARATOR module which is multiplexed with SPI pins
SPPCON = 0x00; // Disabling the SERIAL PERIPHERAL CONTROL module which is multiplexedwith SPI pins
TRISD &= 0xFE; // Clearing 0th pin of PORTD as output ( SS for the slave )
PORTD |= 0x01; // Setting 0th pin of PORTD ( Slave not selected )
SSPSTAT = 0b000000000; // SMP=0(slave mode),CKE=0(transmission on Idle to active clock state),all other bits 0
SSPCON1 = 0x22; // SSPEN = 1 (enable serial port), SSPM[3-0] = 0b0010 (master mode,clcok=FOSC/64), all other bits are zero
}
/*============================================
Function : to send and receive SPI data
=============================================*/
unsigned char spi_data ( unsigned char tx_data )
{
unsigned int data_read3;
cs=0; // Enabling the slave
SSPCON1bits.WCOL=0; //Clear the collision
SSPSTATbits.BF=0; //and Buffer Full control bits.
SSPBUF = tx_data; // put the data in the SSPBUF register which going to be send
while ( !SSPSTATbits.BF ); // wait until the all bits received
SSPSTATbits.BF=0;
data_read1 = SSPBUF; // read the received data from the buffer
data_read2 = SSPBUF; // read the received data from the buffer
data_read3 = data_read1 || (data_read2<<8); // read the received data from the buffer
cs=1; // Disabling the salve
return data_read3;
}
But my data is 16-bit , can't store in unsigned char
unsigned int spi_data ( unsigned char tx_data )
{
unsigned int data_read3;
cs=0; // Enabling the slave
//SSPCON1bits.WCOL=0; //Clear the collision
//SSPSTATbits.BF=0; //and Buffer Full control bits.
SSPBUF = tx_data; // put the data in the SSPBUF register which going to be send
while ( !SSPSTATbits.BF ); // wait until the all bits received
//SSPSTATbits.BF=0;
data_read1 = SSPBUF; // read the received data from the buffer
SSPBUF = tx_data; // put the data in the SSPBUF register which going to be send
while ( !SSPSTATbits.BF ); // wait until the all bits received
data_read2 = SSPBUF; // read the received data from the buffer
data_read3 = data_read1 || (data_read2<<8); // read the received data from the buffer
cs=1; // Disabling the salve
return data_read3;
}