mankmanky1
New Member
Hi there
I am new to serial communication and I am trying to do a project where I can interface matlab with my pic18f4431 micro. I am having a problem setting up my pic to receive data serially as it fails to load properly via my bootloader program...
The code is below:
#include <htc.h>
#include<stdio.h>
void main(void)
{
ANSEL0=0b00000000;
TRISA = 0b00000000;
RCSTA=0b10010000;
TXSTA=0b00100000;
SPBRG=0x0F;
wait:
if(PIR1bits.RCIF==0)
{
goto wait;
}
PORTA=RCREG;
}
I was hoping this would program the pic to receive data serially...
My matlab on the other hand I think is ok. I have programmed matlab to send information serially via matlab to my pic using a vector that contains the bytes to be sent...
Do I have to send data via matlab in a vector or is there another way?
The matlab code is below:
b=[7 4];
s = serial('COM2');
set(s,'BaudRate',9600,'DataBits',8,'Parity','none','StopBits',1,'FlowControl','none','InputBufferSize',102400)
fopen(s);
s.Status
if strcmp(s.TransferStatus, 'idle') || strcmp(s.TransferStatus,'read')
fwrite(s,b,'uint8','async');
else
end
stopasync(s)
fclose(s)
delete(s)
clear s
display('finished')
Please can someone help me as I really need some direction
Thanks
I am new to serial communication and I am trying to do a project where I can interface matlab with my pic18f4431 micro. I am having a problem setting up my pic to receive data serially as it fails to load properly via my bootloader program...
The code is below:
#include <htc.h>
#include<stdio.h>
void main(void)
{
ANSEL0=0b00000000;
TRISA = 0b00000000;
RCSTA=0b10010000;
TXSTA=0b00100000;
SPBRG=0x0F;
wait:
if(PIR1bits.RCIF==0)
{
goto wait;
}
PORTA=RCREG;
}
I was hoping this would program the pic to receive data serially...
My matlab on the other hand I think is ok. I have programmed matlab to send information serially via matlab to my pic using a vector that contains the bytes to be sent...
Do I have to send data via matlab in a vector or is there another way?
The matlab code is below:
b=[7 4];
s = serial('COM2');
set(s,'BaudRate',9600,'DataBits',8,'Parity','none','StopBits',1,'FlowControl','none','InputBufferSize',102400)
fopen(s);
s.Status
if strcmp(s.TransferStatus, 'idle') || strcmp(s.TransferStatus,'read')
fwrite(s,b,'uint8','async');
else
end
stopasync(s)
fclose(s)
delete(s)
clear s
display('finished')
Please can someone help me as I really need some direction
Thanks