Kieran
Joined: 28 Nov 2003 Posts: 39 Location: Essex UK
|
PIC18F452 and SPI |
Posted: Wed May 31, 2006 11:52 am |
|
|
The following code repeatedly resets (on watchdog I assume).
If I remove the SPI write all is OK.
Chip errata dosen't metion SPI problems.
Any ideas.
Compiler version 3.241
Code: |
#include <18F452.h>
#device ADC=10
#fuses HS,NOPROTECT,PUT,WDT,WDT64,NOLVP,BROWNOUT,BORV45
#byte PORTA = 0xF80
#byte PORTB = 0xF81
#byte PORTC = 0xF82
#byte PORTD = 0xF83
#byte PORTE = 0xF84
#use delay(clock=20000000, RESTART_WDT)
#use rs232(baud=19200,xmit=PIN_C6,rcv=PIN_C7,errors)
#define IDDRA 0b00100000
#define IDDRB 0b00000011
#define IDDRC 0b10010000
#define IDDRD 0b11111111
#define IDDRE 0b00000000
#define IPORTA 0b00100100
#define IPORTB 0b00001000
#define IPORTC 0b10000000
#define IPORTD 0b00000000
#define IPORTE 0b00000111
#zero_ram
void main(void)
{
int16 k;
restart_WDT();
PORTA = IPORTA;
PORTB = IPORTB;
PORTC = IPORTC;
PORTD = IPORTD;
PORTE = IPORTE;
set_tris_a(IDDRA);
set_tris_b(IDDRB);
set_tris_c(IDDRC);
set_tris_d(IDDRD);
set_tris_e(IDDRE);
printf("Start\r");
setup_spi(0x0000 | SPI_XMIT_L_TO_H | SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_64 | SPI_SS_DISABLED);
while (1)
{
restart_WDT();
spi_write(0xD3);
delay_ms(500);
printf("Loop\r");
}
}
|
|
|