|
|
View previous topic :: View next topic |
Author |
Message |
noyz
Joined: 31 Jan 2009 Posts: 59
|
Problem interfacing 2 PIC |
Posted: Tue Jun 28, 2011 4:56 am |
|
|
PIC 18F2550 -is writer
Code: |
#include <18F2550.h>
#use delay(clock=48 000 000,RESTART_WDT)
#use rs232(baud=115200 ,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#define START_COMM PIN_B0
#define CLOCK_COMM PIN_B1
#define DATA_COMM PIN_B2
const int DELAY_CLOCK=100;
const int NR_BITS_TO_SEND=16;//max 65535 unsigned and signed +/-32767
void init_comunications () {
output_high ( START_COMM );
output_high ( CLOCK_COMM );
output_high ( DATA_COMM );
}
void send_output (int32 watt) {
int counter = 0;
output_low ( START_COMM );
output_high(DATA_COMM);
output_high(CLOCK_COMM);
while (counter < NR_BITS_TO_SEND) {
delay_us ( DELAY_CLOCK );
output_low ( CLOCK_COMM );
if ( bit_test ( watt, counter ) )
output_low ( DATA_COMM );
delay_us ( DELAY_CLOCK );
output_high ( DATA_COMM );
output_high ( CLOCK_COMM );
//starting next clock signal
counter++;
}
output_high(START_COMM);
}
void main () {
init_comunications ();
while (true){
send_output ( 525 );
delay_ms(10);
|
PIC 18F8527 is reader
Code: |
#include <18F8527.h>
#use delay(clock=40 000 000,RESTART_WDT)
#use rs232(baud=115200,xmit=PIN_C6,rcv=PIN_C7,bits=8,restart_wdt,timeout=250)
//rs 232 used only for test in proteus.. i wil not use it in real app
#define START_COMM PIN_E0
#define CLOCK_COMM PIN_E1
#define DATA_COMM PIN_B0
long read_serial () {
int index = 0;
long value = 0;
if ( input ( START_COMM ) )
while (input ( START_COMM )) {
}
while (!input ( START_COMM )) {
if ( input ( CLOCK_COMM ) )
while (input ( CLOCK_COMM )) {
if ( input ( START_COMM ) ) {
break;
break;
}
}
if ( !input ( DATA_COMM ) ) {
bit_set ( value, index );
}
index++;
while (!input ( CLOCK_COMM )) {
}
}
return (value);
}
void main () {
while (true) {
printf ( "reading\r\n" );
long td = read_serial ();
printf ( "%Lu\r\n", td );
}
}
|
i've done this because it seems that serial interrupts doesnt work,
i tryied int rda / rda2
int rtcc does works
and this is a faster and a better way to send data, no errors..
but i'm missing something.. can anywone help me a little bit here ?
this is the output from 2550
Last edited by noyz on Tue Jun 28, 2011 6:52 am; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Tue Jun 28, 2011 5:27 am |
|
|
Quick comments.
You need to 'cleanup' your programs...to make it easier for us to read and figure out what you're doing.
1) get rid of any unused ISRs (like int_TIMER)
2) if you're not using serial then delete the use rs232(...)
3) get rid of any commented out lines ( // ...)
4) get rid of the setup_spi(..), again, you're not using it.
but if using it use the 'mode_0, mode_1' version as it's cleaner and 'industry standard' format.
5) always add the 'errors' option to the use RS232(...) for any program that uses the serial function.
Once that's cleaned up, what is it that you're missing ?
BTW the CCS included example 'ex_sisr.c' int the examples folder does work, 'everyone' has modified it for their programs. |
|
|
noyz
Joined: 31 Jan 2009 Posts: 59
|
|
Posted: Tue Jun 28, 2011 6:52 am |
|
|
Take a look now, i've edited code.
And i know abous sisr but i am telling you it doesn't work, i've modified it for me.
I really need to try this, there is some strange thing that happens on serial, when i read and then try to draw to a screen a graph.
This doesn't have to do with reading.
The value read is ok, but the registers seem to be a little tricky.
...
Never mind.
I just need to make this code work.
So if i am not using uart. Then i will have no registry overwrite. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Tue Jun 28, 2011 4:40 pm |
|
|
I just figured out you're using Proteus..
"//rs 232 used only for test in proteus.. i wil not use it in real app "
if true, then that explains most if not all of the problems you're having.
Get rid of Proteus as it's full of bugs, quirks, etc.
Cut code for real PICs, run them in the real world,you'll save youself dayze of grief !! |
|
|
noyz
Joined: 31 Jan 2009 Posts: 59
|
|
Posted: Wed Jun 29, 2011 3:14 am |
|
|
Yes you may be right but this is a very simple test.
It should work this way.
I know that I am missing something
on the reading part.
One infinite loop:-?
Btw what I was telling you about sisr, was tested on MCU. |
|
|
|
|
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
|