|
|
View previous topic :: View next topic |
Author |
Message |
Thorsten Guest
|
RS232 recieve problem |
Posted: Sun Nov 05, 2006 3:31 am |
|
|
Hi,
i want to save 256bytes, which will recievied over the UART, into an array.
My Problem is that the values which the PIC recieved is not correct. Here is my code. Have anyone an idea?
Regards
Th.
Code: |
#include "main.h"
#zero_ram
unsigned char string[256];
int i = 0;
void main()
{
set_tris_b(0);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_oscillator(False);
#use rs232(baud=1200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9)
while(1)
{
if(kbhit())
{
do
{
string[i] = getc();
}while(++i);
do
{
write_eeprom(i,string[i]);
}while(++i);
}
}
}
|
|
|
|
Ttelmah Guest
|
|
Posted: Sun Nov 05, 2006 3:54 am |
|
|
Start with the character length. Is this 9 bit data? If so, you are going to be losing the MS bit, since you are only storing 8 bits. Also, using 9 bit, will force the system to use the software UART. Does the data have parity?.
Then you wait for kbhit, pointlessly (since once you enter the loop, you then loop for 255 more characters...).
Setting trisb, is basically pointless, unless you have selected fast_io. The compiler will override this as soon as you do any IO on the port. Shouldn't matter, but worth mentioning.
You don't show what chip is involved, or the clock defintions etc.. How is the serial wired. Can you test this, with a single character test, to verify that the hardware is working?.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|