This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430FR5969: SPI/I2C ( Serial) Communication by bit banging method.(MSP430FR5959)

Part Number: MSP430FR5969


Hi all,

I am using MSP430FR5969. I heard that without using hardware i can test the SPI/I2C communication in MSP430. And i thing the name of this method is bit banging. So is this assumption is correct? 

And one more confusion is bit banging is same as a software SPI/I2C or different. what is Software SPI/I2C.  

And i want more information about it. how can i perform with my controller. I just learn theoretically, but i don't know how it will work without Hardware. I have the Coding with hardware but not without hardware.  

Thanks

Anil D. 

  • Hi Anil,

    You accomplish a software SPI/I2C solution through the method of bit banging, which is manually control of the GPIO lines performing the communication. You should always use a hardware solution if possible. There are online examples provided by the community if you would like to proceed with attempting a software bit bang solution.

    Regards,
    Ryan
  • If you search the term "software SPI mSP430" or "user:wg0z" at github.com, youll find some bit-bang SPI examples for low-end MSP430 devices that I have published.

    You may 'friend' me and send a private message if you have questions

  • Hello Ryan,

    I understood the things is that from your comments, If micro-controller is not having port for SPI/I2C, then we manually need the assign the GPIO pins for it. and making the software like that it is supporting for the communication. 

    like by default CLOCK is not going to generate, by using software i need to generate the CLOCK on the GPIO pin. 

    As like 8051 controller. This controller is also not having inbuilt SPI pins.

    Am I right?

    #include<reg51.h>
    #include"delay.h"
    sbit scl=P2^0;
    sbit sda=P2^1;
    void i2c_start(void)
    {
    	scl=0;
    	sda=1;
    	scl=1;
    	sda=0;
    }
    
    void i2c_stop(void)
    {
    	scl=0;
    	sda=0;
    	sda=1;
    	scl=1;
    }
    
    void i2c_bytewrite(char ch)
    {
    	signed int i;
    	for(i=7;i>=0;i--)
    	{
    		scl=0;
    		if(ch&(1<<i))
    		sda=1;
    		else
    		sda=0;
    		
    		scl=1;
    	}
    }
    
    char i2c_byteread(void)
    {
    	signed int i;
    	char ch=0;
    	for(i=7;i>=0;i--)
    	{
    		scl=0;
    		scl=1;
    		if(sda)
    			ch|=1<<i;
    	}
    	return ch;
    }
    
    void i2c_ack(void)
    {
    	scl=0;
    	sda=1;
    	scl=1;
    	while(sda==1);
    }
    
    void i2c_noack(void)
    {
    	scl=0;
    	sda=1;
    	scl=1;
    }
    
    void writebyte_EEPROM(char SA,char mem,char dat)
    {
    	i2c_start();
    	i2c_bytewrite(SA);
    	i2c_ack();
    	i2c_bytewrite(mem);
    	i2c_ack();
    	i2c_bytewrite(dat);
    	i2c_ack();
    	i2c_stop();
    	delay_ms(10);
    }
    
    char readbyte_EEPROM(char SA,char mem)
    {
    	char ch;
    	i2c_start();
    	i2c_bytewrite(SA);
    	i2c_ack();
    	i2c_bytewrite(mem);
    	i2c_ack();
    	i2c_start();
    	i2c_bytewrite(SA|1);
    	i2c_ack();
    	ch=i2c_byteread();
    	i2c_noack();
    	i2c_stop();
    	return ch;
    }
    
    
    
    main()
    {
    	writebyte_EEPROM(0xa0,0x01,'A');
    	P3=readbyte_EEPROM(0xa0,0x01);
    	while(1);
    }
    
    
    

    See the Linked Code, which  i Made for 8051 I2C communication. 

    So this is the only Bit banging method? 

    thanks

    Anil D.

  • Hello Jeff,

    OK thanks for sharing the links. and the thing is

    Micro-controllers don't have the SPI hardware on board(Peripherals pins are not assigned for the SPI communication), then Developer have to simulate it by doing everything manually.(So while a dedicated SPI controller takes care of all the pulses, data shifting and timing, when bit-banging developer have to take every action there self).

    Is my all statements are correct?

    thanks
    Anil D.

  • Your understanding is correct.

  • bit banging.pdf

    Hello Jeff,

    I have make one document on Bit banging on SPI/I2C. According to my understanding i made it. 

    So Please go through it. and this is helpful to everybody in future.

    Thanks 

    Anil D. 

**Attention** This is a public forum