Problem Facing during Link Data From Matlab To DSPIC 30f4011

1 次查看(过去 30 天)
Hello guys, I currently doing some communication between MATLAB and dspic 30f4011, And i dun know how to set up the MATLAB (mfiles R2008 Version) and dspic30f40111 for it to start the UART connection. Here is the some coding i try on it but i still unable to execute. Din't u has any idea about it?
MATLAB Code
==================================================================
function comparison ()
global x1 y1
global turn
turn=0;
s=serial('COM3');
set(s,'BaudRate',4800);
fopen(s);
fprintf(s,'2');
out=fscanf(s);
fclose(s);
========================================================================
DSPIC coding
#include <p30f4011.h>
_FOSC(CSW_FSCM_OFF & XT_PLL8); // 15MHz Crystal with PLLx8 = 30 MIP
_FWDT(WDT_OFF); // Disable Watch-Dog Timer.
_FBORPOR(PBOR_OFF & MCLR_EN);
_FGS(CODE_PROT_OFF);
#define switch2 PORTBbits.RB0
unsigned char data=0;
void Init_PWM(void);
void init_io (void);
void delay(unsigned long data);
void init_uart (void);
unsigned char uart_rec(void);
void uart_send(unsigned char data);
int main()
{
init_io();
Init_PWM(); // Initialize PWM module
init_uart();
uart_send(1);
data=uart_rec();
while(1) // Infinite forever
{
if(data==1||switch2==0)
{
PDC1 =600;
PDC2 =600;
PDC3 =600;
delay(2000000);
PDC1 =1500;
PDC2 =1500;
PDC3 =1500;
delay(2000000);
}
}
}
void init_uart (void)
{
U1BRG = 103; //initialise UART1 8 /16/25/51/ 103
U1MODE = 0x8800;
U1STAbits.UTXEN = 1;
}
unsigned char uart_rec(void) //receive uart value
{
unsigned int rec_data;
while(U1STAbits.URXDA==0); //wait for data
rec_data = U1RXREG;
return rec_data; //return the data received
}
void uart_send(unsigned char data)
{
while(U1STAbits.UTXBF ==1); //only send the new data after
U1TXREG=data; //the previous data finish sent
}
But my circuit no able to run. Has any idea for it?or didn't i miss something?Thank you and has a nice day.
  1 个评论
Walter Roberson
Walter Roberson 2012-5-24
One thing I note is that your MATLAB code does not do anything with the value you read. I have known compilers that would optimize the entire reading call out if the compiler figured the call was not needed. You could _try_ doing something with "s" after you read it, such as displaying it. I don't think it will solve your problem, but it might.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by