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

i2c, spi comunication

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



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

i2c, spi comunication
PostPosted: Fri Jul 06, 2012 7:29 pm     Reply with quote

I want to create communication (using i2c protocol) between pic and a sensor. (The pic is the slave) it will take the values from the sensor.

My problem is that: if I use 2 pics then one is programmed as slave and the other as master, now in the communication with pic and sensor if I program only the pic as slave is ok?????


Furthermore I want to write data to an external memory with SPI, how to do it???



Thanks in advance.
temtronic



Joined: 01 Jul 2010
Posts: 9162
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jul 07, 2012 5:11 am     Reply with quote

1) There are several great examples that CCS supplies in the 'examples' folder. You should look and read each of them to see what is applicable to your project.

2) Always include the PIC type and compiler version when posting a question.You'll get faster, more detailed replies than a 'general' question.

3) Also ,include the peripheral device information as well,in your case the SPI bussed 'external memory'.Again, CCS supplies working example code for probably 99% of the chips you'll use.


4) Search this forum as well as the 'code library' for relevent posts. A lot of code has been submitted to these forums !!
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

i2c, spi comunication
PostPosted: Sat Jul 07, 2012 4:53 pm     Reply with quote

I create a code in which i read values from (adc converter) and I use spi protocol to write these values to an external flash memory (m25p40).

Also I need my data to be able to transmit over rs232.

I have a lot of problems. Is anyone how can help me. I use dspic33 microcontroller. The code is presented below:
Code:

#include <33FJ128GP708.h>

#FUSES NOWDT
#FUSES HS
#FUSES NOPROTECT
#FUSES NOJTAG
#FUSES NODEBUG
#FUSES NOIESO

#use delay(clock=80000000,crystal=12000000)
#use rs232(stream=string,baud=9600,xmit=PIN_B1,RCV=PIN_B2,parity = N, bits=8)
#use SPI(DI=PIN_F7,DO=PIN_F8,CLK=PIN_F6,BITS=10 )

#define memory_select PIN_G4


main()
{
int32 temp_value;
int32 data_i2c;
SET_TRIS_A(0XFF);
SET_TRIS_B(0XFF);

setup_adc_ports(sAN1);
setup_adc(ADC_CLOCK_DIV_8);
setup_spi(SPI_SLAVE|SPI_H_TO_L|SPI_CLK_DIV_4);

for(;;)
{
temp_value=read_adc(sAN2);
delay_us(10);
spi_write(temp_value);
delay_us(10);
}

return 0;
}
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sat Jul 07, 2012 7:43 pm     Reply with quote

Just as a side note, is the external flash just meant as a buffer of sorts or is it for more permanent storage?

I ask only because I'm wondering if you've checked the write endurance of the FLASH you're using.

Cheers,

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

i2c, spi comunication
PostPosted: Mon Jul 09, 2012 12:54 pm     Reply with quote

The flash is for more permanent storage. How to check the write endurance of the flash???


Also how to change my code?
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