UART communication with 18f4550

General discussion on mikroC.
Post Reply
Author
Message
Tore
Posts: 18
Joined: 21 Feb 2005 20:15

UART communication with 18f4550

#1 Post by Tore » 11 May 2010 21:15

Hello!
I am trying to communicate with i device that is sending out a 38 byte code with uart 115200 baudt, 8 data bits, 1 stop bit, and
no parity. I am using a 18f4550. If i am setting up the micro controller to communicate with the pc, it is working fine. But then i am receiving one byte at the time. Is there any one that have some ides to how i should set up when i wane store 38 byte i correct order. I have tried to store the data in array but it seams like its not stored in the right order.
Best Tore

pratik345
Posts: 15
Joined: 18 Mar 2010 04:24

Re: UART communication with 18f4550

#2 Post by pratik345 » 12 May 2010 05:51

hi... have u tried with 9600 baud rate.....
nd send me your code....

Tore
Posts: 18
Joined: 21 Feb 2005 20:15

Re: UART communication with 18f4550

#3 Post by Tore » 12 May 2010 22:42

No! I have not tried that. The chip that i want to communicate with cant be canged to 9600 baudt. When i am using the usart terminal i am able to send end receive 1 byte at the time to the 18f4550
I am adding my code. The code is a result of many modifications. The last thing i tried was to use interrupt and read one byte in to array at the time. And than i used icd to read out the data. I need to read 38 byte in to memory so i can decode the data afterwards.


unsigned short m,k;
unsigned short userRD_buffer[255];

void interrupt() {
if (Usart_Data_Ready()) { // If data is received
userRD_buffer[k] = RCREG; // Read the received data
++k;

}
}//~

void Init_Main() {
// Disable all interrupts
// Disable GIE, PEIE, TMR0IE, INT0IE,RBIE
INTCON = 0;
INTCON2 = 0xF5;
INTCON3 = 0xC0;
// Disable Priority Levels on interrupts
PIE1 = 0;
// Configure all ports with analog function as digital
ADCON1 |= 0x0F;

// Ports Configuration
TRISA = 0;
TRISB = 0;
TRISC = 0xFF;
TRISD = 0xFF;
TRISE = 0x07;

// Enable T0IE
//USART config
TXSTA.SYNC = 0;
TXSTA.BRGH = 1;
RCSTA = 0x98;
BAUDCON.ABDEN = 1;
BAUDCON.BRG16 = 1;
PIE1.RCIE = 1;
SPBRGH = 0x00;
SPBRG = 0x56;
K=0;
}//~
/** Main Program Routine **/

void main() {
Init_Main();
USART_init(115200);
INTCON = 0xD8;
do {

PORTB = 0x00;
Delay_ms(1000);
PORTB = 0xFF;

} while (1);
}//~!
Best Tore

Sobrietytest
Posts: 619
Joined: 05 Jul 2008 06:05
Location: Thailand

Re: UART communication with 18f4550

#4 Post by Sobrietytest » 13 May 2010 10:44

If you download MikroC PRO you will be able to use the UART1_Read_Text() function which will read the entire string in one command.

pratik345
Posts: 15
Joined: 18 Mar 2010 04:24

Re: UART communication with 18f4550

#5 Post by pratik345 » 14 May 2010 05:23

there is a basicllly limitation of usart if u want to transfer file to usart only 3 char is transmitted..

pratik345
Posts: 15
Joined: 18 Mar 2010 04:24

Re: UART communication with 18f4550

#6 Post by pratik345 » 14 May 2010 05:30

hey i have a problem...
i also work with i2c.
but i cant communicate with eeprom 24lc512 with pic 18f4620....
code provided by mikroc is perfect with eeprom 24c02... so can u help me to solve this problem......
here the code is:


so what changed i need to do..... :(


sbit sw at RB3_bit;
sbit sw_Direction at TRISB3_bit;

void main()
{

unsigned char i;
PORTD = 0;
TRISD = 0;
PORTB = 0; // Configure PORTB as output
TRISB = 1;
ADCON1=0x0F;

I2C1_Init(100000); // initialize I2C communication
for(i=0;i<16;i++)
{
I2C1_Start(); // issue I2C start signal
I2C1_Wr(0xA0); // send byte via I2C (device address + W)
I2C1_Wr(i); // send byte (address of EEPROM location)
I2C1_Wr(i); // send data (data to be written)
I2C1_Stop(); // issue I2C stop signal
Delay_ms(1000);
}
Delay_ms(1000);

i=0;
for(i=0;i<16;i++)
{
if(sw == 1)
{
delay_ms(10);
if(sw==1)
{
delay_ms(2000);
pause: if(sw==1)
{
delay_ms(10);
if(sw==1)
{
goto start;
}
}
goto pause;
}
}


start:I2C1_Start(); // issue I2C start signal
I2C1_Wr(0xA0); // send byte via I2C (device address + W)
I2C1_Wr(i); // send byte (data address)
I2C1_Repeated_Start(); // issue I2C signal repeated start
I2C1_Wr(0xA1); // send byte (device address + R)
PORTD = I2C1_Rd(0u); // Read the data (NO acknowledge)
I2C1_Stop();
Delay_ms(1000); // issue I2C stop signal

}
}

Post Reply

Return to “mikroC General”