Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
jadhavrn
PostPosted: Jun 04, 2012 - 07:44 AM
Newbie


Joined: Sep 23, 2011
Posts: 6


Hi,

I've got a Butterfly and want to communicate with an ATmega8535 over the hardware SPI interface.

Do I need to disable/remove the on board data flash to do this (since its already hooked up to the SPI interface)?

also as Butterfly works on 3.3v and Atmega 8535 on 5v is additional circuit like pull-ups are required??
 
 View user's profile Send private message  
Reply with quote Back to top
js
PostPosted: Jun 04, 2012 - 07:50 AM
10k+ Postman


Joined: Mar 28, 2001
Posts: 20311
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)

Quote:
Butterfly works on 3.3v and Atmega 8535 on 5v is additional circuit like pull-ups are required??
You can run the Atmega 8535 at 3.3V or you can use level translator chips if you MUST have the 2 chips running at different VCC.

_________________
John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
smileymicros
PostPosted: Jun 04, 2012 - 04:19 PM
Raving lunatic


Joined: Nov 17, 2004
Posts: 6137
Location: Great Smokey Mountains.

Also note that 5V is known to kill the Butterfly DataFlash.

Smiley

_________________
FREE TUTORIAL: 'Quick Start Guide for Using the WinAVR C Compiler with ATMEL's AVR Butterfly' AVAILABLE AT: http://www.smileymicros.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
jadhavrn
PostPosted: Jun 13, 2012 - 07:06 AM
Newbie


Joined: Sep 23, 2011
Posts: 6


thanks for reply.
I dont need dataflash in my project so should i operate it on 5V??

Also I want to use PB4 as chip select for 8535
so did following modifications in code

#define SS_HARDWARE_PORT PORTB
#define SS_HARDWARE_PIN PORTB4
#define SS_HARDWARE_DDR DDB4

void SPI_MasterTransmit(char cData)
{

/* Start transmission */
// select slave
// Select slave
SS_HARDWARE_PORT &= (0<<SS_HARDWARE_PIN);

SPDR = cData;

/* Wait for transmission complete */
while(!(SPSR & (1<<SPIF)));

// deselect slave
SS_HARDWARE_PORT |= (1<<SS_HARDWARE_PIN);

}


but my LCD on butterfly stops working until i comment
follwing statments

// Select slave
SS_HARDWARE_PORT &= (0<<SS_HARDWARE_PIN);

// deselect slave
SS_HARDWARE_PORT |= (1<<SS_HARDWARE_PIN);



[url]http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=121834
 
 View user's profile Send private message  
Reply with quote Back to top
MBedder
PostPosted: Jun 13, 2012 - 07:10 AM
Raving lunatic


Joined: Nov 02, 2009
Posts: 3239
Location: Zelenograd, Russia


_________________
Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.
 
 View user's profile Send private message  
Reply with quote Back to top
jadhavrn
PostPosted: Jun 13, 2012 - 07:14 AM
Newbie


Joined: Sep 23, 2011
Posts: 6


my LCD on butterfly stops working until i comment
following statements in SPI_MasterTransmit();


// Select slave
SS_HARDWARE_PORT &= (0<<SS_HARDWARE_PIN);

// deselect slave
SS_HARDWARE_PORT |= (1<<SS_HARDWARE_PIN);



Code:
// ***********************************************************
// Project:
// Author:
// Module description:
// ***********************************************************

#include <avr\io.h>      // Most basic include files
#include <avr\interrupt.h> // Add the necessary ones
#include "LCD_functions.h"
#include "LCD_driver.h"
#include "LCD_global.h"

#define DDR_SPI DDRB
#define DD_MISO DDB3
#define DD_MOSI DDB2
#define DD_SCK  DDB1
#define DD_SS  DDB4
#define DD_Flash  DDB0


void SPI_MasterInit(void);
void SPI_MasterTransmit(char);
void ClockChange(void);


/************************************************************/
/*!   
   \def spi_hard_clear_ss()
   Defines a macro to clear the hardware slave select pin
   \def spi_hard_set_ss()
   Defines a macro to set the hardware slave select pin
*/
/************************************************************/
#define SS_HARDWARE_PORT PORTB
#define SS_HARDWARE_PIN PORTB4
#define SS_HARDWARE_DDR DDB4


char txbuff[]="SPIreceived";
char cData,tData;
int zz=0;j=0;

// ***********************************************************
// Main program
//
//int
main(void) {
   
             ClockChange();
             zz=0;
          cData="0";
             
                       // initialize the LCD
         LCD_Init();                 
            SPI_MasterInit();
   
 // enable global interrupt
    sei();

   
 LCD_puts("Main",1);// text to be displayed in the LCD
 
  for(zz = 0; zz < 5; zz++)
 {         LCD_puts("Transmitting",1);
        tData=txbuff[zz];
        SPI_MasterTransmit(tData);   
   }
   

LCD_puts("SEND",1);   // text to be displayed in the


while(1)
{
zz=0;
}



}




void SPI_MasterInit(void)
{
/* Set SS,MOSI and SCK output, all others input */
DDR_SPI = (0<<DD_MISO)|(1<<DD_MOSI)|(1<<DD_SS)|(1<<DD_SCK);

/* Enable SPI, Master, set clock rate fck/32 */
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
//SPSR=(1<<SPI2X);

}




void SPI_MasterTransmit(char cData)
{

/* Start transmission */
// select slave

[b][color=red]SS_HARDWARE_PORT &= (0<<SS_HARDWARE_PIN)[/color];[/b]

LCD_puts("master",1);
SPDR = cData;
/* Wait for transmission complete */
while(!(SPSR & (1<<SPIF)));


// deselect slave
[b][color=red]SS_HARDWARE_PORT |= (1<<SS_HARDWARE_PIN);[/color] [/b]


}



void ClockChange(void)
{
// boost IntRC to 8Mhz
        CLKPR = (1<<CLKPCE);     // set Clock Prescaler Change Enable
       
     // set prescaler = 4, Inter RC 8Mhz / 4 = 2Mhz
        CLKPR = (1<<CLKPS1);

}

 
 View user's profile Send private message  
Reply with quote Back to top
larryvc
PostPosted: Jun 13, 2012 - 07:16 AM
Raving lunatic


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA

Please do not Crosspost!!!

_________________
Larry

Those afraid to embrace the future will quickly fade into the past. - larryvc


Last edited by larryvc on Jun 13, 2012 - 07:47 AM; edited 1 time in total
 
 View user's profile Send private message  
Reply with quote Back to top
js
PostPosted: Jun 13, 2012 - 07:44 AM
10k+ Postman


Joined: Mar 28, 2001
Posts: 20311
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)

I have deleted the other thread, please stick to this one now.

_________________
John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
larryvc
PostPosted: Jun 13, 2012 - 08:02 AM
Raving lunatic


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA

jadhavrn wrote:
thanks for reply.
I dont need dataflash in my project so should i operate it on 5V??

Do you want to destroy the DataFlash?
smileymicros wrote:
Also note that 5V is known to kill the Butterfly DataFlash.

Smiley

Do not use 5V if you want the DataFlash to function in the future.

_________________
Larry

Those afraid to embrace the future will quickly fade into the past. - larryvc
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Jun 13, 2012 - 09:14 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62209
Location: (using avr-gcc in) Finchingfield, Essex, England

Code:
// Select slave
SS_HARDWARE_PORT &= (0<<SS_HARDWARE_PIN);

Time for you to hop over to the Tutorial Forum and read the Bit Manipulation 101 thread I think.

The above is NOT the way to make that pin go low. The following is the way to do it:
Code:
// Select slave
SS_HARDWARE_PORT &= ~(1<<SS_HARDWARE_PIN);

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
smileymicros
PostPosted: Jun 13, 2012 - 05:17 PM
Raving lunatic


Joined: Nov 17, 2004
Posts: 6137
Location: Great Smokey Mountains.

The unattributed code that your code comes from worked fine and all you need to do is change the defined device and the associated device specific port defines. That is, assuming the 8325 isn't too alien from the rest of the AVR clan.

Random cuts and pastes like this are unhelpful:
Code:
/************************************************************/
/*!   
   \def spi_hard_clear_ss()
   Defines a macro to clear the hardware slave select pin
   \def spi_hard_set_ss()
   Defines a macro to set the hardware slave select pin
*/
/************************************************************/
#define SS_HARDWARE_PORT PORTB
#define SS_HARDWARE_PIN PORTB4
#define SS_HARDWARE_DDR DDB4
You've taken the documentation from a macro and put it ahead of three unrelated defines. Doesn't make sense doe it?

Smiley

_________________
FREE TUTORIAL: 'Quick Start Guide for Using the WinAVR C Compiler with ATMEL's AVR Butterfly' AVAILABLE AT: http://www.smileymicros.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits