Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

USART data into SPI - PIC18F4520 - c18

Status
Not open for further replies.

prem0siva

Newbie level 2
Joined
Oct 6, 2009
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Detroit
Activity points
1,300
Hi,

I am using PIC18f4520 and Microchip mcc18 compiler.

I am able to write data into spi sucessfully using the library spi.h

WriteSPI(0xff); //the value is 1111 1111

How can I write a value which i have received from my USART ? I am able to receive as char. But how can i convert to hex? is conversion to hex is the only way to use my SPI?

I am using it to control a 2 channel 12bit DAC (LTC1448). I would like to use the library of c18.

I have been struggling for 4 weeks.

Thanks,
~Prem
 

character have a hex value, they are interpreted inside the CPU to hex value not characters, I think if you took the value from the USART and send it to the SPI it will output it.
just read from the USART and store in an array (just for buffering) then send the data to SPI.
 

Thank you elrayes. I have given below the code I used.


#include <p18f4520.h>
#include <delays.h>
#include <spi.h>
#include <usart.h>

#pragma config WDT=OFF
#pragma config OSC=HS

void main(void)
{

unsigned int Data[3];

TRISB = 0b00000000; TRISA = 1;
TRISC = 0x00;
PORTBbits.RB0 = 1;

OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, 10);


while(1)
{

while(!DataRdyUSART());
getsUSART(Data,3);

PORTBbits.RB0 = 0;

OpenSPI(SPI_FOSC_64, MODE_01, SMPMID);

Delay10KTCYx(100);
WriteSPI(Data[0]);

Delay10KTCYx(100);
WriteSPI(Data[1]);

Delay10KTCYx(100);
WriteSPI(Data[2]);

CloseSPI();
PORTBbits.RB0 = 1;
Delay10KTCYx(100);

}
}

This is the code I am using. I think I am storing the recevied value from USART to an array Data[3]. But it is not working.
 

try to re-build the source files of the API's your are using in your project, sometimes these problems isn't from the code but from compiler issues.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top