View previous topic :: View next topic |
Author |
Message |
krakatau
Joined: 19 Feb 2009 Posts: 9
|
16 bit transfer with rs232 |
Posted: Wed Mar 11, 2009 10:11 am |
|
|
hi,
My question is very short.
I want to 16bit transfer with rs232 protocol, is it possible?
What do I do?
I will use to pic16f876 to 16bit shift register.
16bit transfer or 8bit 8bit transfer.
thanks |
|
|
Guest
|
|
Posted: Wed Mar 11, 2009 10:54 am |
|
|
Hi krakatau, you have to send 8 bits and then another 8 bits. If you want to recieve it in a 16 bits register you have to do something like this:
var=BufferReception;
var=(var<<8)| BufferReception;
your 'var' has the 16bits data you wanted to send. But you have to be careful with the first 8 bits that you send, in this example I send the upper 8bits and then the lower. |
|
|
Ttelmah Guest
|
|
Posted: Wed Mar 11, 2009 11:05 am |
|
|
Remember also, that with RS232, there are start and stop bits each side of the data. To transfer directly to a shift register, you'd really want to be using SSP, then a clock is provided as well, and if you implement slave select, this can reset the shift register. Again 8 bit transfers, but you simply operate the select line, and send two transfers, which will include the clocks to operate the register.
Best Wishes |
|
|
krakatau
Joined: 19 Feb 2009 Posts: 9
|
|
Posted: Thu Mar 12, 2009 1:26 am |
|
|
first of all thanks your quickly replies.. i suppose rs232 can't 16bit transfer directly.it s true? i worked that ;
16bit data, from PC to pic16f876 to another pic16f876 and then this 16bit data will send to 16bit shift register. so 16f876-16f876-shiftregister-on the shiftregister_output.
yesterday i wrote like above code;
for master;
Code: | #use rs232(baud=9600, parity=N, xmit=pin_c6, rcv=pin_c7)
int16 x;
while(1)
{
x=0xffff;
putc(x);
} |
for slave;
Code: | #use rs232(baud=9600, parity=N, xmit=pin_c6, rcv=pin_c7)
int16 y;
int z;
while(1)
{
y=getc();
z=make8(y, 1);
output_b(z);
} |
i tired 16bit transfer between two pics
it didn't work.
i read your message.
i will send 8bit transfer from pc to pic. and then 8bit to another pic then first 8bit transfer to shift register(Q15....Q8) immediately second 8bit transfer to shiftregister (Q7....Q0)
is it true???
last question;
i'll send clock from any pin (for example pin_b7) true?
already now thanks a lot guys..[/code] |
|
|
krakatau
Joined: 19 Feb 2009 Posts: 9
|
|
Posted: Fri Mar 13, 2009 7:49 am |
|
|
have you any idea?? |
|
|
Ttelmah Guest
|
|
Posted: Fri Mar 13, 2009 8:55 am |
|
|
You have already had a full reply. Look at the first line, of the very first reply, for what you are missing.
Best Wishes |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Fri Mar 13, 2009 9:35 am |
|
|
RS232 or any other serial transfer can't send 16 bits at a time. It cant even send 8 bits at a time. Serial transfers send ONE bit at a time. The usual PIC or PC hardware UART does a serial to 8 bit parallel conversion, but a custom software UART could operate with any word width desired.
Look up the CCS functions make8() and make16(). _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
krakatau
Joined: 19 Feb 2009 Posts: 9
|
|
Posted: Fri Mar 13, 2009 10:05 am |
|
|
I found my code is wrong because putc() function's back value have to be 8bit. Its a CCS rule. I tried 16bit transfer. I'll send 8bit, 8bit data transfer, I'm forced to.
I'm ok. Thanks a lot. |
|
|
Ttelmah Guest
|
|
Posted: Fri Mar 13, 2009 3:58 pm |
|
|
Not a 'CCS Rule'. A rule if you are talking to an interface supporting byte transfers. Same happens in C on the PC, if you are talking to the RS232...
Best Wishes |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Fri Mar 13, 2009 4:03 pm |
|
|
The UART hardware parallel to serial shift register only supports 8 bits as well.... It has NOTHING to do with CCS. |
|
|
|