We present an approach to spin dynamics by extending the optical Bloch equations for the driven two-level system to derive microscopic expressions for the transverse and longitudinal spin relaxation times. This is done for the 6-level system of electron and hole subband states in a semiconductor or a semiconductor quantum structure to account for the degrees-of-freedom of the carrier spin and the polarization of the exciting light and includes the scattering between carriers and lattice vibrations on a microscopic level. For the subsystem of the spin-split electron subbands we treat the electron-phonon interaction in second order and derive a set of equations of motion for the 2x2 spin-density matrix which describes the electron spin dynamics and contains microscopic expressions for the longitudinal (T_1) and the transverse (T_2) spin relaxation times. Their meaning will be discussed in relation to experimental investigations of these quantities.