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.

TM4C123GH6PM: SSI communication on 1 board

Part Number: TM4C123GH6PM


Hello TI community, 

I am trying to implement the basics of SPI communication. I have 1 tm4c123 Launchpad.

Can i send the data from SSI0 to SSI1 on the same board considering one is a master and the other is slave ?

if so, do i need to connect slave select signal SS ? 

Regards, 

Sarea

  • It is believed that "vendor examples" - and more likely "poster attempts here" (found via use of the Forum Search Box) will reveal & detail such, "SPIn to SPIm" implementations.

    As to Slave Select - it is your "Master SPI" which must drive/control that pin - is that not so? While the Master device "includes" an SPI "Slave, chip_select" pin - that proves (often) too inflexible - and a Master GPIO is employed, instead. (and it is this "Master GPIO" which connects to the Slave's SS pin (be that another SPI port (w/in the same MCU) or a (more usual) external, Slave I2C device.)

    To clarify - "Yes - there is a connection between your MCU's Master SPI (select GPIO which serves as Slave CS) and the MCU's Slave SPI (SS pin.)"
    While neither firm nor I have physically implemented such "SPIn to SPIm - single MCU connection" the "broader (more usual) implementation demands that the Master Side SPI generate a proper "CS" signal to the (normal) external chip, Slave.
  • Hi cb1,

    Thanks for your replay. I have used SSI0 as a slave, SSI1  as a master and PD6 as SS signal.

    I have connected the wiring as the following:

    SS signal from PD6 to PA3(SS pin of the slave)

    PD0 to PA2 (clock pins on master and slave)

    PD3 to PA4 (TX of master to RX of slave)

    PD2 to PA5 (RX of master to TX of slave)

    but when i write to Data Register of master trying to send byte its value doesn't change!

    and no transmitting occur

    could you please help ? what should i do to have successful data transfer?

    here is the initialization code and the main

    void SSI0_Init(void){
    
        // settings for TX, RX, SS, CLK in GPIO PORTA
        SYSCTL_RCGCSSI_R |= 0x01 ;      // clock on SSI0 module
        SYSCTL_RCGCGPIO_R |= 0x01 ;     // clock on PORTA
        GPIO_PORTA_AFSEL_R |= 0x3c ;    // alt. function for PORTA 2, 3, 4, 5
        GPIO_PORTA_PCTL_R |= 0x00222200;
        GPIO_PORTA_DEN_R |= 0x3c ;      // digital enable
    
        // settings of SSI0 module
        SSI0_CR1_R = 0 ;                // disable during configuration
        SSI0_CC_R = 0 ;                 // system clock
        SSI0_CPSR_R = 2 ;               // prescaler div by 2
        SSI0_CR0_R |= 0x07 ;            // 8MHZ, SPI mode, 8 bit frame
        SSI0_CR1_R |= 0x04 ;            // set as a slave
        SSI0_CR1_R |= 0x02 ;            // enable
    }
    
    void SSI1_Init(void){
    
        // settings for TX, RX, SS, CLK in GPIO PORTA
        SYSCTL_RCGCSSI_R |= 0x02 ;      // clock on SSI1 module
        SYSCTL_RCGCGPIO_R |= 0x08 ;     // clock on PORTD
        GPIO_PORTD_AFSEL_R |= 0x0F ;    // alt. function for PORTD 0,1,2,3
        GPIO_PORTD_PCTL_R |= 0x02;
        GPIO_PORTD_DEN_R |= 0x0F ;      // digital enable
    
        // settings for PD6 as SS signal
        GPIO_PORTD_DIR_R |= 0x40 ;      // PD6 output
        GPIO_PORTD_DEN_R |= 0x40 ;      // digital enable PD6
        GPIO_PORTD_DATA_R |= 0x40 ;     // keep SS idle high
    
        // settings of SSI1 module
        SSI1_CR1_R = 0 ;                // disable during configuration
        SSI1_CC_R = 0 ;                 // system clock
        SSI1_CPSR_R = 2 ;               // prescaler div by 2
        SSI1_CR0_R |= 0x07 ;            // 8MHZ, SPI mode, 8 bit frame
        SSI1_CR1_R = 0x00 ;             // set as a master
        SSI1_CR1_R |= 0x02 ;            // enable
    }
    
    int main(){
        SSI0_Init();
        SSI1_Init();
    
        while(1){
        // set ss low
        GPIO_PORTD_DATA_R &= ~0x40 ;            // ss low
        while ((SSI1_SR_R & 0x02) == 0 ){}      //wait till fifo not full
        SSI1_DR_R = 0xff ;                      // send char a
        while (SSI1_SR_R & 0x10){}              // wait for TX complete
        GPIO_PORTD_DATA_R |= 0x40 ;             // ss high
    
        uint32_t data ;
        while ((SSI0_SR_R & 0x04) == 0){}       // wait for not empty fifo flag
        data = SSI0_DR_R ;                      // data reading
        int i = data ;
        }
    }
    

    Regards,

    Sarea

  • My friend - while myself/others, "Feel your pain" - is not much of that pain self-inflicted?

    You have - for unexplained reason - chosen a code style (Direct Register Manipulation, "DRM") which has been long noted as (both) archaic & inefficient.     May we ask how this "DRM" style was chosen?

    You arrived here, "Seeking to build your understanding of SPI operation."     And such is a proper goal.      However - your "Method of Attack" (exclusive use of DRM) proves ineffective - as your arrival here (minus any SPI success) proves.     And this "FAILURE of Posters to Succeed" - when "DRM" is employed - is "legendary!"     The vendor here especially discourages DRM's use - they too having noted the "unacceptable failure rate" - predictably resulting from DRM!

    You have a clear alternative -  this vendor's extensive, "Tried, True, Tested" API.    In contrast - any developer's use of DRM - yields, "UNTried, (often) UNtrue, & UNtested" results.    How can that be good?

    The API provides comprehensive code examples (SPI being well covered) and this is thoughtfully grouped by, "MCU Peripheral" - both speeding & easing your "REAL Learning!"    (not the "fictionalized learning" - over-promised/promoted by DRM - and so rarely delivered!)

    You will find model, SPI-based code examples at: TivaWare\examples\peripherals\spi.    The API is deeply & clearly explained/detailed w/in the "Peripheral Driver Library User's Guide" - firm/I consider this REQUIRED Reading ... even its Mastery.

    Few here will devote the "Excessive Time & Effort" - required to review your DRM code.    Such is "not" being "mean" - such IS in recognition that a vastly superior method (the API) - lies at your doorstep...

  • Cb1
    Thanks for your long replay.
    Since i am a beginner and want to learn the very basics of communication protocols, i always preferred to write my first code in a direct accessing register mode to make sure of strong understanding and build the basics. The second step is being TivaWare using the guide and its interesting example and i do the same thing with every topic i learn in MCU programming.
    anyway.. Thanks again for your help

    Regards,
    Sarea
  • Thank you, my friend.

    May I (again) challenge your belief that (someway) "Starting w/DRM" ... "Makes sure of strong understanding?"

    If such "strong understanding" would result - would not your code, "Perform to full expectation?"       Alas - it does not (in fact - does not (even) "come close") - and the clock ticks - and strong understanding proves, "Nowhere to be seen!"        (Do not ALL "facts in evidence" - point in this inescapable direction?)

    May I suggest a "hybrid method" (employed by our intern & new staff hires) which includes "Joint Use" of the API (to select the most appropriate API functions - as the project requires) and (then) a serious visit to the MCU Manual's "Register Presentation" - to add further "light" to the API's "broader brush!"

    It is expected that this "hybrid method" will, "Speed, Ease & Enhance" your learning - leading to, "mastery!"        And FAR FASTER & MORE EFFICIENTLY than, "DRM Alone!"     (your visit here - courtesy of the "Failed DRM Only approach" - clearly suggests such - does it not?)

  • CB1,
    I "#LIKE" your excellent suggestion. Your hybrid method is how I learned and it provides for both quick development and deep understanding. Excellent suggestion!
  • Bob,

    I have told my heart to, "Be still!"     Much thanks for your kind "#LIKE" - along w/your agreement with the "Speeded, Eased & Enhanced" understanding this "Hybrid" method insures.    (API selective use - followed by the proper review of,  "Registers in play.")

    "DRM-Only" proponents, "Shut  their eyes" to the MAJOR GAINS which such "Hybrid Method" provides!       (i.e. Hybrid extracts the "best" features, advantages, & insights - from each coding method.)     The API is "world-class!"     Its: "depth, breadth and ability to remarkably, "Speed & Ease" code development" proves "irresistible" - rejecting its use borders upon, "foolhardy!" 

    Such "Hybrid" election (proper mix of the API followed by Register review)  proves (near) ideal - even if - and especially if - "missed"  (possibly deliberately) by those with, "Shut eyes!"