CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Problems with power up .. losing spi initialization

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Eugeneo
Guest







Problems with power up .. losing spi initialization
PostPosted: Tue Apr 19, 2005 10:27 pm     Reply with quote

I've written a program using a pic16f819. For some reason everything everything works except on ocasion, the spi port is not initialized. When this happens the program functions normally but with no spi interface.

Here is a segment of my program. As you can see I've setup the spi port 3 times and the problem seems to get better by 70%. Has anybody seen this probem before.


void main(void)
{
OSCCON=OSC_8MHZ;
setup_spi(SPI_SLAVE | SPI_H_TO_L | SPI_CLK_DIV_16);
enable_interrupts(INT_SSP);
setup_spi(SPI_SLAVE | SPI_H_TO_L | SPI_CLK_DIV_16);
enable_interrupts(INT_SSP);
setup_spi(SPI_SLAVE | SPI_H_TO_L | SPI_CLK_DIV_16);
enable_interrupts(INT_SSP);

setup_wdt(WDT_144MS);

setup_timer_1(T1_INTERNAL | T1_DIV_BY_8); setup_ccp1(CCP_COMPARE_INT); // Configure CCP1 to set
enable_interrupts(INT_CCP1);
set_timer1(0);
CCP_1=500;
setup_spi(SPI_SLAVE | SPI_H_TO_L | SPI_CLK_DIV_16);
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL); do
{
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 20, 2005 12:59 am     Reply with quote

Sounds like a wacky problem. What's your version of the compiler ?
gator
Guest







PostPosted: Thu Jan 24, 2008 9:39 pm     Reply with quote

Has anybody else seen this problem? I am experiencing the same issue.

Sometimes the spi will not work on reset but everything else appears to function properly. Once the spi gets up and running though it works without any problems.

The code I am using is:

#byte SSPSTAT = 0x94
#byte SSPCON = 0x14
#byte TRISA = 0x85
#byte TRISC = 0x87
#byte SSPBUF = 0x13
#byte PIR1 = 0x0c
#byte PIE1 = 0x8c
#byte PORTB = 0x06 // 106
#byte PCON = 0x8E
#byte STATUS = 0x03
#byte TRISB = 0x86

#define SSPIF 0x08

char DVD_BufferIn[BUFFER_SIZE];
char DVD_BufferOut[BUFFER_SIZE];
char Vault_Buffer[BUFFER_SIZE];
int DVD_counterIn;
int DVD_counterOut;
int Vault_counter;
int test_led_glow;
short int SPI_READ_DATA;
short int SPI_SEND_DATA;
byte SSPBUF_OUT;
byte DVD_response_is_ready;
byte DVD_message_started;
byte Vault_message_started;
byte tempcount;
byte reset_POR;
byte reset_BOR;
byte reset_TO;
byte reset_PD;

#define NUL 0x0
#define STX 0x2
#define ETX 0x3
#define ENQ 0x5
#define STATUS_LED PIN_B0 // output
#define POR_RESET PIN_B1 // POR RESET
#define BOR_RESET PIN_B2 // BOR RESET
#define TO_RESET PIN_B4 // TO
#define PD_RESET PIN_B5 // PD


// ****************************************************************************
//
// init_hardware - Hardware initialization
//
// Initializes the hardware to its correct state.
//
// ****************************************************************************
init_hardware()
{
SSPCON &= 0xDF;
SSPCON = 0x04;
SSPCON |= 0x20;
SSPBUF &= 0x00; // clear SSPBUF
SSPSTAT = 0x00;
TRISC = TRISC & 0xDF;
TRISC = TRISC | 0x08 ;
ADCON1 |= 0x0F;
TRISA &= 0x00;
TRISA |= 0x20;

TXSTA = TXSTA & 0xEF; // set synchronous SCI mode
TXSTA = TXSTA | 0x04;
RCSTA = RCSTA | 0x10;
SPBRG = SPBRG | 0x0B;
}


// ****************************************************************************
//
// main - main control loop
//
****************************************************************************

main()
{
TRISB &= 0xC8; // SET TRISB to O/P 0xuu00u000
DVD_counterIn = 0;
DVD_counterOut = 0;
Vault_counter = 0;
tempcount = 0;
test_led_glow = 0;

#use delay(clock=3680000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7)
// wait till power stable
delay_ms(1000);

// clear buffers
for (byte i = 0; i < BUFFER_SIZE; i++)
{
DVD_BufferIn[i] = 0x0;
DVD_BufferOut[i] = 0x0;
Vault_Buffer[i] = 0x0;
}

init_hardware();
delay_ms(100);

enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
enable_interrupts(INT_SSP);

reset_BOR = PCON & 0x01;
reset_POR = PCON & 0x02;
reset_TO = STATUS & 0x10;
reset_PD = STATUS & 0x08;

PCON |= 0x03;

while(1)
{;}
}


#INT_SSP
void spi_isr()
{
byte tempdata;
byte i;

if ( SSPSTAT & 0x01 )
{
tempdata = SSPBUF;
if ( DVD_response_is_ready == TRUE )
{
SSPBUF = DVD_BufferIn[DVD_counterIn];

if ( DVD_BufferIn[DVD_counterIn] == ETX )
{
DVD_response_is_ready = FALSE;
DVD_counterIn= 0;
}
else
DVD_counterIn++;
}
else
SSPBUF = 0xAA;

// process the new incoming data
if ( tempdata != ENQ )
{
switch ( tempdata )
{
case STX: Vault_Buffer[0] = STX;
Vault_counter = 1;
Vault_message_started = TRUE;
break;

case ETX: if ( Vault_message_started == TRUE )
{
Vault_Buffer[Vault_counter] = ETX;
for (i = 0; i <Vault_counter> 1 && Vault_counter > Vault_Buffer[1]) || Vault_counter >= (BUFFER_SIZE - 1) )
{
Vault_counter = 0;
Vault_message_started = FALSE;
for (i = 0; i <BUFFER_SIZE>= BUFFER_SIZE - 1 )
DVD_counterIn = 0;
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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