i am trying to write a small program to test serial communication between dsPIC30F2020 and MATLAB via FT232.
As per the program, a random number is sent from matlab to the PIC. On reception of the number via UART, an interrupt is generated and an LED connected to pin B0 should glow.
But, am unable to do so. can someone please tell me where am i going wrong?
clc
clear all
s = serial('COM3');
set(s,'BaudRate',115200);
fopen(s);
% ENTER PIC RELATED CODE HERE
a= 001;
fwrite(s,a,'int8','async');
x=1;
k=fread(s);
disp(k);
pause(5);
fclose(s)
delete(s)
and the connection between FT232 and PIC are as follows:
re: problem with UART RECEPTION: using dsPIC30F2020, matlab, FT232 & c30 compiler
The first thing is that you are not calling the 'initUart' function from 'main'.
Which compiler are you using?
Can you use the debugger to step into the code to make sure that it is running at all. Also you are not reading the character form the Rx buffer - for some devices and in some circumstances (not sure if this is the case for you but...) this will cause a 'receive buffer overflow' that can stop further reception. You need to handle reception and errors correctly.
If a variable is altered in an ISR then it should be declared as volatile (and there are other cases where volatile should be used - I suggest you read up on those sometime).
Why are you connecting the \MCLR\ to the DTR line via a capacitor! At best this is useless but more likely it has the potential to be resetting your MCU at totally unexpected times.
At the early stages of learning and development I would suggest that you do NOT use interrupts - they add another layer of complexity that is not required. Put a test into the main loop for when the URXDA bit is set and then read a character from the Rx buffer. This is easier to debug as well.
Can you put a scope on the line from the FT232 to the MCU to make sure that it is sending a character?
Also can you transmit characters from the UART (0x55 or 0xaa are good choices as they give you a reasonable square-wave signal) and use a scope to make sure that the BAUD rate is correct?
Are you sure you have the oscillator set up correctly? What is the crystal frequency?
With some compilers you need to tell the 'delay' functions what the oscillator/instruction frequency is - often with a #define of the FCY symbol or similar. Do you need to do that to get an accurate delay?
Susan