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 CCS Technical Support

SPI Problem from PIC16F886 to MAXQ3180
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 18, 2008 2:52 pm     Reply with quote

Post your latest test program.
boulder



Joined: 15 Mar 2008
Posts: 53

View user's profile Send private message

PostPosted: Tue Mar 18, 2008 6:31 pm     Reply with quote

Here is my latest code:
Code:

#include "16F886.h"
#include <stdio.h>

#use delay(clock=2000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#fuses INTRC, NOWDT, PUT, MCLR, NOPROTECT, NOCPD, NOBROWNOUT, NOIESO, NOFCMEN, NOLVP, NOWRT

   int8 i=0;
   int8 Sendtab[6]={0x10,0x26,0x00,0x00,0x00,0x00};
   int8 Receivetab[6];

void main()
{

   setup_oscillator( OSC_2MHZ );
   
   output_high(PIN_C3);
   output_high(PIN_C5);
   output_high(PIN_B5);

   setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_XMIT_L_TO_H | SPI_CLK_DIV_16);

   output_low(PIN_B5);   //Slave Select

   for(i=0;i<6;i++)
      Receivetab[i] = spi_read(Sendtab[i]);         
   
   output_high(PIN_B5);

   for(i=0;i<6;i++)
    printf("%x\n",Receivetab[i]);    //Print out data

    printf("%x\n",*(0x14));           //SSPCON
    printf("%x\n",*(0x94));          //SSPSTAT
    printf("%x\n\n",*(0x13));       //SSPBUF
 
   while(1);
}


I am expecting 6 received data from slave, 0xC1, 0xC2, 0X4E, 0X41, 0x39 and 0x35. But all data is 0x00. SSPCON value is 0x21, SSPSTAT is 0x40, and SSPBUF is 0. One thing I don't understand is that I can see received data from slave on an oscilloscope, but the reading from pickit serial is 0.

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 18, 2008 7:11 pm     Reply with quote

The data sheet says you must have a delay of 25 us after each byte.
You don't have the delay in your code. I suggested this in a previous
post. See the 2nd paragraph in the left column on page 14 of the Maxim
data sheet.

I also suggested that you insert a delay of 100 ms at the start of your
program, to give the Maxim chip time to finish any internal reset or
initialization process.
boulder



Joined: 15 Mar 2008
Posts: 53

View user's profile Send private message

PostPosted: Tue Mar 18, 2008 8:22 pm     Reply with quote

I just tried it, and it still does not work. Here is my latest code:
Code:

#include "16F886.h"
#include <stdio.h>

#use delay(clock=2000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#fuses INTRC, NOWDT, PUT, MCLR, NOPROTECT, NOCPD, NOBROWNOUT, NOIESO, NOFCMEN, NOLVP, NOWRT

   int8 i=0;
   int8 Sendtab[6]={0x10,0x26,0x00,0x00,0x00,0x00};
   int8 Receivetab[6];

void main()
{
   delay_ms(100);
   setup_oscillator( OSC_2MHZ );
   
   output_high(PIN_C3);
   output_high(PIN_C5);
   output_high(PIN_B5);

   setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_XMIT_L_TO_H | SPI_CLK_DIV_16);

   output_low(PIN_B5);   //Slave Select

   for(i=0;i<6;i++)
   {
      Receivetab[i] = spi_read(Sendtab[i]);
      delay_us(25);
   }         
   
   output_high(PIN_B5);

   for(i=0;i<6;i++)
    printf("%x\n",Receivetab[i]);    //Print out data

    printf("%x\n",*(0x14));           //SSPCON
    printf("%x\n",*(0x94));          //SSPSTAT
    printf("%x\n\n",*(0x13));       //SSPBUF
 
   while(1);
}

I still read the same value, 0x00, and I still can see 6 clocked in data on an oscilloscope. I used ST's arm7 as master one week ago and it was successful with the same settings and logic.

Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 18, 2008 8:35 pm     Reply with quote

Do you have a short program, written in C source code, for the ARM7 ?
If so, post it. Or if it's on the net, then post a link to it.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Mar 18, 2008 8:59 pm     Reply with quote

Quote:
One thing I don't understand is that I can see received data from slave on an oscilloscope, but the reading from pickit serial is 0.
If I understand the MAXQ3180 correctly then it will start sending a 0xC1 byte as soon as it is selected and gets clock pulses. So even if the PIC is not sending any valid data the MAXQ3180 will respond with some data. The PIC only receiving '0' is strange. It could be the SPI-mode is wrong, but you already tried all 4 combinations... Just to make sure, can you tell us which pin numbers of the PIC are connected to what pin numbers of the MAXQ3180?
boulder



Joined: 15 Mar 2008
Posts: 53

View user's profile Send private message

PostPosted: Tue Mar 18, 2008 9:08 pm     Reply with quote

Here is my ST ARM7 code, the chi STR712.
Code:

#include "71x_lib.h"

int main (void)
{

  u8 Sendtab[6]={0x10,0x26,0x00,0x00,0x00,0x00};
  u8 Receivetab[6];
  u8 i=0, x, z;
  u16 j;

/*-------------------------------------------------------------------------
  Check Different Clock, expect every clock is 2MHZ.
--------------------------------------------------------------------------*/
  u32 MCLKval;
  u32 APB1CLKval;
  u32 APB2CLKval;
  #ifdef DEBUG
  debug();
  #endif
 
 
  MCLKval=RCCU_FrequencyValue (RCCU_MCLK);
  APB1CLKval=RCCU_FrequencyValue (RCCU_FCLK);
  APB2CLKval=RCCU_FrequencyValue (RCCU_PCLK);
 
  printf("%i  %i  %i  \n", MCLKval,APB1CLKval, APB2CLKval);
  APB_ClockConfig( APB1, ENABLE,  BSPI1_Periph ) ;


/* ---------------------------------------------------------------------------------------
   Configure Pin Ports
--------------------------------------------------------------------------------------- */
   GPIO_Config (GPIO1, 0x0001<<8, GPIO_OUT_PP);
   GPIO_Config (GPIO0, 0x00FF, GPIO_AF_PP);

   GPIO_BitWrite(GPIO1, 8, 1);                   //Slave Select

/* -------------------------------------------
Configure BSPI1 as a Master
------------------------------------------- */

/* Initialize BSPI0 */
   BSPI_Init   ( BSPI1 ) ;

/* Configure Baud rate Frequency: ---> APB1/16 */
   BSPI_ClockDividerConfig ( BSPI1,16);           //Get 125kHz spi speed

/* Enable BSPI0 */
   BSPI_Enable ( BSPI1 , ENABLE );

/* Configure BSPI0 as a Master */
   BSPI_MasterEnable ( BSPI1,ENABLE);

/* Configure the clock to be inactive high */
   BSPI_ClkActiveHigh(BSPI1,DISABLE);

/* Disable capturing the first Data sample on the first edge of SCK */
   BSPI_ClkFEdge(BSPI1,DISABLE);

/* Set the word length to 8 bit */
   BSPI_8bLEn(BSPI1,ENABLE);

/*  Configure the depth of transmit to 6 bytes */
   BSPI_TrFifoDepth(BSPI1,6);
/* Point on the word to transit */

   BSPI_RcFifoDepth(BSPI1,6);


/* ---------------------------------------------
Send and read 6 bytes of buffer
--------------------------------------------- */
   GPIO_BitWrite(GPIO1, 8, 0);

   for(i=0;i<6;i++)
   {

     BSPI_WordSend(BSPI1, Sendtab[i]);

     while(BSPI_FlagStatus(BSPI1, BSPI_TFE)==RESET);     //Check if transmit buffer empty

     while(BSPI_FlagStatus(BSPI1, BSPI_RFNE)==RESET);    //Check if receive buff full

     Receivetab[i] = BSPI_WordReceive(BSPI1);
   }
   
   GPIO_BitWrite(GPIO1, 8, 1);                         

   for(i=0;i<6;i++)                                     //Print out data
      printf("Data%i = %x\n", i, Receivetab[i]);
   
   while (1);
}


I wonder if the PCM library function has a bug because I can see 6 correct clocked in data from slave on oscilloscope, but they becomes 0x00 on pickit serial.
boulder



Joined: 15 Mar 2008
Posts: 53

View user's profile Send private message

PostPosted: Wed Mar 19, 2008 9:59 am     Reply with quote

I just figured out why 6 clocked in data is 0x00. It's because I am using Pickit Serial which has impedance. One of Pickit Serial pins is connected SPI_DI pin, pin_C4, it causes clocked in data signal voltage level below 2 volts by impedance. That's why I always read 0x00 on Pickit Serial display but see correct data bits on oscilloscope with low level voltage at the same time. After removing Pickit Serial, clocked in data signal is normal, LEDs shows all 6 clocked in data is read correctly.

Thanks.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Mar 19, 2008 10:34 am     Reply with quote

Glad you found the cause of the problems. This is one of those bang-your-head-against-wall moments.

Quote:
One of Pickit Serial pins is connected SPI_DI pin
Just wondering which Pickit pin you had connected and why? To me none of the Pickit pins does seem as a logical candidate for this connection.
boulder



Joined: 15 Mar 2008
Posts: 53

View user's profile Send private message

PostPosted: Wed Mar 19, 2008 11:03 am     Reply with quote

Pickit's pin4 is connected to SDI, and pin5 is connected to SCK. I did not connected them, the demo board is designed this way. If you look at 28-pin Demo board schematic on USER's GUIDE, you will know what I mean. I should have read the schematic first.
Sarada



Joined: 02 Jun 2008
Posts: 2

View user's profile Send private message

PostPosted: Fri Jul 04, 2008 5:15 am     Reply with quote

hi all i just started using the Maxq3180 IC can anybody please post the circuit for the IC.

Thanks in advance
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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