|
|
View previous topic :: View next topic |
Author |
Message |
Jim Oram
Joined: 01 Jan 2010 Posts: 24 Location: Charlotte
|
SPI and UART1 |
Posted: Tue Apr 02, 2013 9:49 am |
|
|
Hi Ttelmah,
Thank you for making it clear about the relation between spi and uart1.
I have made sure your directives are implemented.
But it seems that I am making very large strides backward.
Now when I program the 18F26J50 chip (via ICSP) .. it programs ok, no errors, but the chip does not come up and run.
So I back tracked to code that blinked the LEDs and that does nothing.
I figured the chip went bad so I installed a new chip.
Same thing. Programs but does not do anything, not even blink the LEDs.
I checked the PCB thinking something came loose, seems ok.
Somehow I must find out what went wrong ... will get back to you when I can at least blink an LED.
Thanks Kindly, for all your help, you are most appreciated.
more on all this later when I get it fixed,
Jim _________________ Jim Oram |
|
|
Jim Oram
Joined: 01 Jan 2010 Posts: 24 Location: Charlotte
|
SPI and UART2 test code for 18F26J50 |
Posted: Tue Apr 02, 2013 11:54 am |
|
|
++++++++++++++++++++++++++
Jim, please learn to use Code blocks. Mod is tired of doing it for you.
Highlight code lines with mouse.
Press Code button.
Preview to check it, and post.
Edit this post and add Code block.
- Forum Moderator
++++++++++++++++++++++++++
Ttelmah,
Your suggestions have bee implimented with appreciation.
For debugging I added some LED indicators so I could trace the code on my PCB.
It appears to hang up on the fputc() function.
#case
#include <18F26J50.h>
#FUSES NOWDT,NOPROTECT,INTRC
#use delay(clock=8000000)
#define GRNLED PIN_B6
#define REDLED PIN_B7
#pin_select TX2=PIN_C0 // I/O pin assignment:
#pin_select RX2=PIN_C1 // use Uart 2 connect to PIN_C0 and C1
#use rs232 (baud=4800,parity=N,UART2,bits=8,errors,stream=COMM2)
char x;
void main(){
setup_uart(FALSE); //needs to be here.
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16);
while(TRUE){
output_high(GRNLED); // green led off
output_low(REDLED); // indicate start fputc() RED on
fputc('1',COMM2); // fputc to COMM2 .... HANGS HERE
output_low(GRNLED); // indicate char sent, end fputc()
output_high(REDLED); // RED off
delay_ms(2000);
output_high(GRNLED); // GREEN off
output_low(REDLED); // indicate start fprintf()
fprintf(COMM2," hello CCS\r\n");
output_low(GRNLED); // indicate end fprintf()
output_high(REDLED); // RED off
delay_ms(2000);
output_high(GRNLED);
output_low(REDLED); // indicate start spi_write()
spi_write('X'); // write X to to the SPI pin 18. HANGS !
output_high(REDLED); // RED off
delay_ms(2000);
output_low(GRNLED); // indicate end spi_write()
delay_ms(5000);
}
}
Your suggestions are very much desired...
This is wearing me out... :-)
Thank You very Kindly,
Jim _________________ Jim Oram |
|
|
Jim Oram
Joined: 01 Jan 2010 Posts: 24 Location: Charlotte
|
|
Posted: Tue Apr 02, 2013 2:27 pm |
|
|
Moderator: ok, I will highlight the 'code' and press the code button as instructed. Hope it works.
Ttelmah,
Somehow I got the board working again.
Your suggestions have been implimented with appreciation.
For debugging I added some LED indicators so I could trace the code on my PCB.
It appears to hang up on the fputc() function.
Code: | #case
#include <18F26J50.h>
#FUSES NOWDT,NOPROTECT,INTRC
#use delay(clock=8000000)
#define GRNLED PIN_B6
#define REDLED PIN_B7
#pin_select TX2=PIN_C0 // I/O pin assignment:
#pin_select RX2=PIN_C1 // use Uart 2 connect to PIN_C0 and C1
#use rs232 (baud=4800,parity=N,UART2,bits=8,errors,stream=COMM2)
char x;
void main(){
setup_uart(FALSE); //needs to be here.
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16);
while(TRUE){
output_high(GRNLED); // green led off
output_low(REDLED); // indicate start fputc() RED on
fputc('1',COMM2); // fputc to COMM2 .... HANGS HERE
output_low(GRNLED); // indicate char sent, end fputc()
output_high(REDLED); // RED off
delay_ms(2000);
output_high(GRNLED); // GREEN off
output_low(REDLED); // indicate start fprintf()
fprintf(COMM2," hello CCS\r\n");
output_low(GRNLED); // indicate end fprintf()
output_high(REDLED); // RED off
delay_ms(2000);
output_high(GRNLED);
output_low(REDLED); // indicate start spi_write()
spi_write('X'); // write X to to the SPI pin 18. HANGS !
output_high(REDLED); // RED off
delay_ms(2000);
output_low(GRNLED); // indicate end spi_write()
delay_ms(5000);
}
} | Your suggestions are very much desired...
This is wearing me out... :-)
Thank You very Kindly,
Jim
Jim Oram Posted: Tue Apr 02, 2013 9:49 am Post subject: SPI and UART1
--------------------------------------------------------------------------------
Hi Ttelmah,
Thank you for making it clear about the relation between spi and uart1.
I have made sure your directives are implemented.
But it seems that I am making very large strides backward.
Now when I program the 18F26J50 chip (via ICSP) .. it programs ok, no errors, but the chip does not come up and run.
So I back tracked to code that blinked the LEDs and that does nothing.
I figured the chip went bad so I installed a new chip.
Same thing. Programs but does not do anything, not even blink the LEDs.
I checked the PCB thinking something came loose, seems ok.
Somehow I must find out what went wrong ... will get back to you when I can at least blink an LED.
Thanks Kindly, for all your help, you are most appreciated.
more on all this later when I get it fixed,
Jim _________________ Jim Oram |
|
|
Jim Oram
Joined: 01 Jan 2010 Posts: 24 Location: Charlotte
|
18F26J50 SPI and USART2 now working, modified program |
Posted: Tue Apr 02, 2013 10:02 pm |
|
|
Ttelmah,
I kept hammering on this code until it works now.
Some things look strange in the code ,,, but it works, sending data at 4800 baud to the Comm Operator program and sending data via SPI to the digital storage scope. Thanks to you and everybody at the forum, with your guidance it now works.
Code: | #case
#include <18F26J50.h>
#FUSES NOWDT,NOPROTECT,HS // INTRC
#use delay(clock=8000000)
#pin_select TX2=PIN_C0 // I/O pin assignment:
#pin_select RX2=PIN_C1 // use Uart 2 connect to PIN_C0 and C1
#byte PIR3 = 0xFA4 // TX2IF bit 4 FA4h PIR3 bit_clear(PIR3, TX2IF) TX2IF
#define TX2IF 4
//#define TXEN 5
//#define SPEN 7
#define GRNLED PIN_B6
#define REDLED PIN_B7
#use rs232 (baud=4800,parity=N,UART2,bits=8,errors,stream=COMM2)
// The above baud setting does not seem to work correctly.
// must include setup_uart(4800,COMM2) after setup_usart(FALSE).
char x;
void main(){
set_tris_a(0x07); // 07);
set_tris_b(0xE3); // E3); // 1110 0011
set_tris_c(0x36); // ); // 0011 0110 C0 and C1 are mapped to USART2
setup_uart(FALSE); // needs to be here.
setup_uart(4800,COMM2); // necessary for correct baud rate on USART2
//
for(x=0 ; x < 100 ; x++){
output_low(GRNLED);
fputc('S',COMM2); // send 'S' to USART2
delay_ms(4);
//spi_write('X'); // no write X to to the SPI pin 18.
delay_ms(50);
output_high(GRNLED);
delay_ms(80);
}
// seems necessary to split to two routines. ?
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16);
for(x=0 ; x < 170 ; x++){
output_low(GRNLED);
delay_ms(4);
spi_write('X'); // write X to to the SPI pin 18.
//bit_clear(PIR3, TX2IF);
delay_ms(50);
output_high(GRNLED);
delay_ms(50);
}
// Now do this loop, mix USART2 and SPI.
while(TRUE){
output_high(GRNLED); // green led off
output_low(REDLED); // indicate start fputc() RED on
fputc('1',COMM2); // fprintf(COMM2,"1 "); // ; // fputc to COMM2 .... HANGS HERE
output_low(GRNLED); // indicate char sent, end fputc()
output_high(REDLED); // RED off
delay_ms(100);
output_high(GRNLED); // GREEN off
output_low(REDLED); // indicate start fprintf()
fprintf(COMM2," hello SPI+USART2\r\n");
output_low(GRNLED); // indicate end fprintf()
output_high(REDLED); // RED off
//delay_ms(200);
output_high(GRNLED);
output_low(REDLED); // LED indicates start spi_write()
spi_write('X'); // write X to to the SPI pin 18. HANGS !
output_high(REDLED); // RED off
delay_ms(200);
output_low(GRNLED); // indicate end spi_write()
delay_ms(300);
}
} |
_________________ Jim Oram |
|
|
|
|
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
|